Submission #8363528


Source Code Expand

Copy
#include <cstdio>
#include <algorithm>
#include <utility>
#include <vector>

#define FOR(i, n) for(int i = 0; i < n; i++) 

#define pow CHANGETHENAMESTUPID

using namespace std;

typedef pair<int,int> pii;
typedef long long ll;

const int N = 1e5 + 100;

int n;
int a[N], b[N];

void load() {
	scanf("%d", &n);
	FOR(i, n) scanf("%d", a + i);
	FOR(i, n) scanf("%d", b + i);
}

bool solve() {
	vector<pii> bs;
	FOR(i, n) bs.push_back({b[i], i});
	sort(bs.begin(), bs.end());
	vector<int> as(n);
	FOR(i, n) as[i] = a[bs[i].second];
	sort(a, a + n);
	FOR(i, n) if (a[i] > bs[i].first) return false;
	for (int i = 1; i < n; i++) if (a[i] == a[i-1]) return true;
	vector<pii> ass;
	FOR(i, n) ass.push_back({as[i], bs[i].second});
	sort(ass.begin(), ass.end());
	vector<pii> cyc;
	cyc.push_back({0, ass[0].second});
	vector<int> has(n);
	FOR(i, n) has[ass[i].second] = i;
	while (true) {
		pii p = cyc.back();
		int kuda = bs[p.first].second;
		int kudass = has[kuda];
		if (kudass == 0) break;
		cyc.push_back({kudass, ass[kudass].second});
	}
	//for (auto x : cyc) printf("%d %d\n", x.first, x.second);
	if ((int)cyc.size() < n-1) return true;
	for (int i = 1; i < n; i++) if (ass[i].first <= bs[i-1].first) return true;
	return false;
}

int main() {
	load();
	printf("%s\n", (solve()) ? "Yes" : "No");
	return 0;
}

Submission Info

Submission Time
Task C - Swaps
User biljazovic
Language C++14 (GCC 5.4.1)
Score 600
Code Size 1371 Byte
Status AC
Exec Time 51 ms
Memory 4852 KB

Compile Error

./Main.cpp: In function ‘void load()’:
./Main.cpp:21:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
./Main.cpp:22:30: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  FOR(i, n) scanf("%d", a + i);
                              ^
./Main.cpp:23:30: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  FOR(i, n) 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 51 ms 4724 KB
in02.txt AC 46 ms 4596 KB
in03.txt AC 46 ms 4596 KB
in04.txt AC 49 ms 4724 KB
in05.txt AC 49 ms 4852 KB
in06.txt AC 50 ms 4724 KB
in07.txt AC 49 ms 4852 KB
in08.txt AC 48 ms 4852 KB
in09.txt AC 47 ms 4724 KB
in10.txt AC 47 ms 4724 KB
in11.txt AC 49 ms 4596 KB
in12.txt AC 45 ms 4596 KB
in13.txt AC 42 ms 3572 KB
in14.txt AC 46 ms 4084 KB
in15.txt AC 44 ms 4084 KB
in16.txt AC 47 ms 4084 KB
in17.txt AC 44 ms 3956 KB
in18.txt AC 46 ms 4084 KB
in19.txt AC 44 ms 3956 KB
in20.txt AC 47 ms 4212 KB
in21.txt AC 43 ms 4852 KB
in22.txt AC 41 ms 4848 KB
in23.txt AC 40 ms 4724 KB
in24.txt AC 38 ms 4596 KB
in25.txt AC 40 ms 4724 KB
in26.txt AC 13 ms 1528 KB
in27.txt AC 14 ms 1532 KB
in28.txt AC 20 ms 2296 KB
in29.txt AC 2 ms 384 KB
in30.txt AC 3 ms 512 KB
in31.txt AC 24 ms 2040 KB
in32.txt AC 13 ms 1660 KB
in33.txt AC 18 ms 2296 KB
sample01.txt AC 1 ms 256 KB
sample02.txt AC 1 ms 256 KB
sample03.txt AC 1 ms 256 KB