Contest Duration: - (local time) (120 minutes) Back to Home

Submission #8357890

Source Code Expand

Copy
```#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>

using namespace std;

typedef long long i64;
typedef i64 int_t;
typedef vector<int_t> vi;
typedef vector<vi> vvi;

typedef pair<int_t, int_t> pi;

#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)

int main(int argc, char *argv[]) {
i64 N, i;
cin >> N;
vi A0(N), B0(N), A(N), B(N);
REP(0, N, i)
cin >> A0[i];
REP(0, N, i)
cin >> B0[i];

// B is increasing
vector<pi> Bp(N);
REP(0, N, i)
Bp[i] = make_pair(B0[i], i);
sort(all(Bp));

REP(0, N, i) {
B[i] = Bp[i].first;
A[i] = A0[Bp[i].second];
}

i64 ans = 0;
set<pi> As;
REP(0, N, i) {
As.insert(make_pair(A[i], i));
}
//
REP(0, N, i) {
//cout << As.size() << endl;
if(A[i] > B[i]) {
// find max j which satisfies A[j] <= B[i]
// find min j A[j+1] > B[i]
auto lb = As.lower_bound(make_pair(B[i], N));
if(lb == As.begin()) {
cout << "No" << endl;
return 0;
}
lb--;
i64 j = lb->second;
As.erase(As.find(make_pair(A[i], i)));
As.erase(As.find(make_pair(A[j], j)));
As.insert(make_pair(A[i], j));
swap(A[i], A[j]);
//cout << "swap " << i << " " << j << endl;
ans++;

}
else {
As.erase(As.find(make_pair(A[i], i)));
}
}

cout << ((ans <= (N - 2)) ? "Yes" : "No") << endl;
return 0;
}
```

#### Submission Info

Submission Time 2019-11-09 21:45:57+0900 C - Swaps nakari_1124 C++14 (GCC 5.4.1) 600 1677 Byte AC 180 ms 12672 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 165 ms 12672 KB
in02.txt AC 140 ms 10240 KB
in03.txt AC 144 ms 10112 KB
in04.txt AC 148 ms 10752 KB
in05.txt AC 150 ms 10880 KB
in06.txt AC 146 ms 10752 KB
in07.txt AC 132 ms 11136 KB
in08.txt AC 125 ms 10752 KB
in09.txt AC 127 ms 10624 KB
in10.txt AC 125 ms 10752 KB
in11.txt AC 164 ms 10112 KB
in12.txt AC 137 ms 10112 KB
in13.txt AC 142 ms 10240 KB
in14.txt AC 152 ms 10880 KB
in15.txt AC 143 ms 10112 KB
in16.txt AC 166 ms 10368 KB
in17.txt AC 141 ms 10240 KB
in18.txt AC 156 ms 10752 KB
in19.txt AC 142 ms 10368 KB
in20.txt AC 157 ms 11008 KB
in21.txt AC 180 ms 10880 KB
in22.txt AC 163 ms 10880 KB
in23.txt AC 161 ms 10752 KB
in24.txt AC 153 ms 10112 KB
in25.txt AC 156 ms 10624 KB
in26.txt AC 37 ms 3200 KB
in27.txt AC 38 ms 3456 KB
in28.txt AC 45 ms 4608 KB
in29.txt AC 2 ms 384 KB
in30.txt AC 6 ms 768 KB
in31.txt AC 78 ms 6272 KB
in32.txt AC 42 ms 3712 KB
in33.txt AC 62 ms 4992 KB
sample01.txt AC 1 ms 256 KB
sample02.txt AC 1 ms 256 KB
sample03.txt AC 1 ms 256 KB