Submission #8353311


Source Code Expand

Copy
#include<bits/stdc++.h>
#define MAXN 100005
#define INF 1000000000
#define MOD 998244353
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int n,a[MAXN],b[MAXN],c[MAXN],d[MAXN];
map<int,int> mpc,mpd;
int perm[MAXN];
bool vis[MAXN];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        c[i]=a[i];
    }
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&b[i]);
        d[i]=b[i];
    }
    sort(c+1,c+n+1); sort(d+1,d+n+1);
    for(int i=1;i<=n;i++)
    {
        if(c[i]>d[i])
        {
            puts("No");
            return 0;
        }
    }
    for(int i=2;i<=n;i++)
    {
        if(c[i]<=d[i-1])
        {
            puts("Yes");
            return 0;
        }
    }
    for(int i=1;i<=n;i++)
    {
        mpc[c[i]]=i; mpd[d[i]]=i;
    }
    for(int i=1;i<=n;i++)
    {
        perm[mpd[b[i]]]=mpc[a[i]];
    }
    memset(vis,false,sizeof(vis));
    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        if(!vis[i])
        {
            int cur=i;
            do
            {
                vis[cur]=true;
                cur=perm[cur];
            }while(!vis[cur]);
            cnt++;
        }
    }
    if(cnt==1) puts("No"); else puts("Yes");
    return 0;
}

Submission Info

Submission Time
Task C - Swaps
User Roundgod
Language C++14 (GCC 5.4.1)
Score 600
Code Size 1343 Byte
Status
Exec Time 163 ms
Memory 11648 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:16:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
                   ^
./Main.cpp:19:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&a[i]);
                          ^
./Main.cpp:24:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&b[i]);
                          ^

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample01.txt, sample02.txt, sample03.txt
All 600 / 600 sample01.txt, sample02.txt, sample03.txt, in01.txt, in02.txt, in03.txt, in04.txt, in05.txt, in06.txt, in07.txt, in08.txt, in09.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in20.txt, in21.txt, in22.txt, in23.txt, in24.txt, in25.txt, in26.txt, in27.txt, in28.txt, in29.txt, in30.txt, in31.txt, in32.txt, in33.txt, sample01.txt, sample02.txt, sample03.txt
Case Name Status Exec Time Memory
in01.txt 152 ms 11136 KB
in02.txt 145 ms 10752 KB
in03.txt 141 ms 10624 KB
in04.txt 152 ms 11264 KB
in05.txt 159 ms 11392 KB
in06.txt 153 ms 11136 KB
in07.txt 163 ms 11648 KB
in08.txt 147 ms 11264 KB
in09.txt 144 ms 11008 KB
in10.txt 153 ms 11136 KB
in11.txt 145 ms 10624 KB
in12.txt 139 ms 10624 KB
in13.txt 143 ms 10624 KB
in14.txt 158 ms 11392 KB
in15.txt 144 ms 10624 KB
in16.txt 148 ms 10880 KB
in17.txt 144 ms 10752 KB
in18.txt 156 ms 11264 KB
in19.txt 149 ms 10752 KB
in20.txt 160 ms 11520 KB
in21.txt 35 ms 1792 KB
in22.txt 33 ms 1792 KB
in23.txt 32 ms 1792 KB
in24.txt 30 ms 1664 KB
in25.txt 31 ms 1792 KB
in26.txt 31 ms 3456 KB
in27.txt 35 ms 3584 KB
in28.txt 52 ms 4864 KB
in29.txt 2 ms 512 KB
in30.txt 5 ms 896 KB
in31.txt 77 ms 6656 KB
in32.txt 10 ms 768 KB
in33.txt 14 ms 896 KB
sample01.txt 1 ms 384 KB
sample02.txt 1 ms 256 KB
sample03.txt 1 ms 256 KB