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 AC
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]);
                          ^

Judge Result

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