Submission #170914

#TimeUsernameProblemLanguageResultExecution timeMemory
170914sochoSorting (IOI15_sorting)C++14
20 / 100
53 ms632 KiB
#include "sorting.h" #include "bits/stdc++.h" using namespace std; const int MXN = 200005; int n, m; int seq[MXN]; vector<pair<int, int> > plan; vector<pair<int, int> > ans; bool works(int sw) { // cout << "try: " << sw << endl; ans.clear(); int nsw[n]; for (int i=0; i<n; i++) nsw[i] = seq[i]; int where[n]; for (int i=0; i<sw; i++) { int a = plan[i].first, b = plan[i].second; swap(nsw[a], nsw[b]); } for (int i=0; i<n; i++) { // cout << nsw[i] << ' '; where[nsw[i]] = i; } // cout << endl; int need = 0; for (int i=0; i<n; i++) { if (nsw[i] == i) continue; need++; int ati = nsw[i]; int whei = where[i]; where[ati] = whei; where[i] = i; nsw[i] = i; nsw[whei] = ati; ans.push_back(make_pair(i, whei)); } // cout << "req: " << need << " have: " << sw << endl; // if (sw == 3) return true; return need <= sw; } int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { n = N; m = M; for (int i=0; i<n; i++) seq[i] = S[i]; for (int i=0; i<m; i++) { plan.push_back(make_pair(X[i], Y[i])); } for (int j=0; j<=M; j++) { if (works(j)) { for (int i=0; i<j; i++) { if (i < ans.size()) { P[i] = ans[i].first; Q[i] = ans[i].second; } else { P[i] = 0; Q[i] = 0; } } return j; } } }

Compilation message (stderr)

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:55:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (i < ans.size()) {
         ~~^~~~~~~~~~~~
sorting.cpp:68:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
#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...