Submission #257856

#TimeUsernameProblemLanguageResultExecution timeMemory
257856shrek12357정렬하기 (IOI15_sorting)C++14
0 / 100
2 ms512 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 = 1e6 + 11; //ifstream in(".in"); //ofstream out(".out"); int pos[H], n, m; pi query[H], ans[H], a[H]; vector<pair<int, int>> toChange; vector<int> xAns, yAns; bool check(int mid, int nums[], int n, int x[], int y[]) { int in[n + 11], out[n + 11]; for(int i = 0; i < n; i++){ in[i] = out[i] = nums[i]; } for(int i = 0; i < mid; i++){ swap(out[query[i].first], out[query[i].second]); } for (int i = 0; i < mid; i++) { int a = nums[x[i]]; nums[x[i]] = nums[y[i]]; nums[y[i]] = a; } int adjList[n + 5]; // can optimize later for (int i = 0; i < n; i++) { adjList[i] = nums[i]; } int counter = 0; bool viz[n + 5]; for (int i = 0; i < n; i++) { viz[i] = false; } int k = 0; for(int i = 0; i < n; i++){ if(viz[i])continue; vector<int>cur; int v = out[i]; while(v != i){ cur.push_back(v); v = out[v]; } cur.push_back(v); for(int j = sz(cur) - 1; j > 0; j--){ a[k++] = {cur[0], cur[j]}; } for(auto it : cur)viz[it] = 1; } if(k > mid) return false; for (int i = 0; i < n; ++i){ pos[in[i]] = i; } for(int i = 0; i < k; i++){ //His move int x = query[i].ff, y = query[i].ss; swap(in[x], in[y]); pos[in[x]] = x; pos[in[y]] = y; //My move x = pos[a[i].ff], y = pos[a[i].ss]; swap(in[x], in[y]); pos[in[x]] = x; pos[in[y]] = y; ans[i] = {x, y}; } while(k < mid)ans[k++] = {0, 0}; return 1; } int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { int lo = -1; int hi = M; while (lo + 1 < hi) { int mid = (lo + hi) / 2; if (check(mid,S,N,X,Y)) { hi = mid; } else { lo = mid; } //toChange.clear(); } check(hi, S, N, X, Y); //getAns(hi, S, N, X, Y); for (int i = 0; i < xAns.size(); i++) { P[i] = xAns[i]; Q[i] = yAns[i]; } return hi; }

Compilation message (stderr)

sorting.cpp: In function 'bool check(int, int*, int, int*, int*)':
sorting.cpp:28:56: warning: declaration of 'n' shadows a global declaration [-Wshadow]
 bool check(int mid, int nums[], int n, int x[], int y[]) {
                                                        ^
sorting.cpp:22:13: note: shadowed declaration is here
 int pos[H], n, m;
             ^
sorting.cpp:39:7: warning: declaration of 'a' shadows a global declaration [-Wshadow]
   int a = nums[x[i]];
       ^
sorting.cpp:23:22: note: shadowed declaration is here
 pi query[H], ans[H], a[H];
                      ^
sorting.cpp:83:13: warning: declaration of 'int x' shadows a parameter [-Wshadow]
         int x = query[i].ff, y = query[i].ss;
             ^
sorting.cpp:28:46: note: shadowed declaration is here
 bool check(int mid, int nums[], int n, int x[], int y[]) {
                                              ^
sorting.cpp:83:30: warning: declaration of 'int y' shadows a parameter [-Wshadow]
         int x = query[i].ff, y = query[i].ss;
                              ^
sorting.cpp:28:55: note: shadowed declaration is here
 bool check(int mid, int nums[], int n, int x[], int y[]) {
                                                       ^
sorting.cpp:43:6: warning: variable 'adjList' set but not used [-Wunused-but-set-variable]
  int adjList[n + 5]; // can optimize later
      ^~~~~~~
sorting.cpp:47:6: warning: unused variable 'counter' [-Wunused-variable]
  int counter = 0;
      ^~~~~~~
sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:117:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < xAns.size(); i++) {
                  ~~^~~~~~~~~~~~~
#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...