Submission #8356530


Source Code Expand

Copy
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int N;
    while(cin >> N){
        vector<pair<int,int>> A, B;
        for(int i=0;i<N;i++){
            int t; cin >> t;
            A.emplace_back(t, i);
        }
        for(int i=0;i<N;i++){
            int t; cin >> t;
            B.emplace_back(t, i);
        }
        sort(A.begin(), A.end());
        sort(B.begin(), B.end());
        vector<int> next(N);
        bool ok = true;
        bool chk = true;
        for(int i=N-1;i>=0;i--){
            if(A[i].first > B[i].first) ok = false;
            else if(i-1 >= 0 && A[i].first <= B[i-1].first) chk = false;
            next[A[i].second] = B[i].second;
        }
        if(chk){
            int size = 0;
            vector<int> visit(N, 0);
            int s = 0;
            while(!visit[s]){
                visit[s] = 1;
                ++size;
                s = next[s];
            }
            if(size == N) ok = false;            
        }
        cout << (ok ? "Yes" : "No") << endl;
    }
}

Submission Info

Submission Time
Task C - Swaps
User pes
Language C++14 (GCC 5.4.1)
Score 600
Code Size 1110 Byte
Status AC
Exec Time 92 ms
Memory 2548 KB

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 91 ms 2548 KB
in02.txt AC 69 ms 2548 KB
in03.txt AC 68 ms 2420 KB
in04.txt AC 72 ms 2548 KB
in05.txt AC 73 ms 2548 KB
in06.txt AC 92 ms 2548 KB
in07.txt AC 76 ms 2548 KB
in08.txt AC 74 ms 2548 KB
in09.txt AC 72 ms 2548 KB
in10.txt AC 75 ms 2548 KB
in11.txt AC 87 ms 2548 KB
in12.txt AC 68 ms 2420 KB
in13.txt AC 68 ms 2548 KB
in14.txt AC 72 ms 2548 KB
in15.txt AC 66 ms 2420 KB
in16.txt AC 89 ms 2548 KB
in17.txt AC 68 ms 2548 KB
in18.txt AC 73 ms 2548 KB
in19.txt AC 69 ms 2548 KB
in20.txt AC 74 ms 2548 KB
in21.txt AC 92 ms 2548 KB
in22.txt AC 73 ms 2548 KB
in23.txt AC 72 ms 2548 KB
in24.txt AC 68 ms 2420 KB
in25.txt AC 71 ms 2548 KB
in26.txt AC 20 ms 892 KB
in27.txt AC 21 ms 892 KB
in28.txt AC 30 ms 1272 KB
in29.txt AC 2 ms 256 KB
in30.txt AC 4 ms 384 KB
in31.txt AC 40 ms 1528 KB
in32.txt AC 23 ms 892 KB
in33.txt AC 31 ms 1400 KB
sample01.txt AC 1 ms 256 KB
sample02.txt AC 1 ms 256 KB
sample03.txt AC 1 ms 256 KB