Submission #252185

#TimeUsernameProblemLanguageResultExecution timeMemory
252185HeheheSorting (IOI15_sorting)C++14
20 / 100
1 ms384 KiB
#include<bits/stdc++.h> //:3 using namespace std; typedef long long ll; #define all(a) (a).begin(), (a).end() #define ff first #define ss second #define pb push_back #define mp make_pair #define rc(s) return cout<<s,0 #define pi pair <int, int> #define sz(x) (int)((x).size()) #include "sorting.h" const int dx[] = {0, 1, 0, -1}; const int dy[] = {1, 0, -1, 0}; const ll H = 2e3 + 11; //ifstream in(".in"); //ofstream out(".out"); int pos[H]; int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { int n = N, m = M, cur = 0; for(int i = 0; i < n; i++){ pos[S[i]] = i; if(X[i] == 0 && Y[i] == 0)cur++; } vector<pi>ans; if(cur == n){//subtask 1, 2 for(int i = 0; i < n; i++){ if(S[i] == i)continue; ans.push_back({i, pos[i]}); int x = i, y = S[i]; swap(S[i], S[pos[i]]); pos[y] = pos[i]; pos[x] = x; } int k = 0; for(auto it : ans){ P[k] = it.ff; Q[k] = it.ss; k++; } return sz(ans); }else{//subtask 3 swap(S[0], S[1]); //Ermek first move pos[S[0]] = 0; pos[S[1]] = 1; ans.push_back({pos[0], 1}); int XX = pos[0], YY = 1; pos[S[1]] = pos[0]; pos[0] = 0; swap(S[XX], S[YY]); swap(S[0], S[1]); //we put 0 on pos 1 then he swaps (0, 1) so we have the form 0, x, .. ans.push_back({pos[1], 1}); int xx = pos[1], yy = 1; pos[S[0]] = pos[1]; pos[1] = 1; swap(S[xx], S[yy]); swap(S[0], S[1]); //we put 1 on pos 1 then he swaps (0, 1) so we have the form 1, 0, .. S[0] = 1; S[1] = 0; for(int i = 2; i < n; i++){ if(S[i] == i)continue; ans.push_back({i, pos[i]}); int x = i, y = S[i]; swap(S[i], S[pos[i]]); pos[y] = pos[i]; pos[x] = x; //his move swap(S[0], S[1]); } if(S[0] != 0)ans.push_back({0, 1}); int k = 0; for(auto it : ans){ P[k] = it.ff; Q[k] = it.ss; k++; } return sz(ans); } }

Compilation message (stderr)

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:26:16: warning: unused variable 'm' [-Wunused-variable]
     int n = N, m = M, cur = 0;
                ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...