제출 #128055

#제출 시각아이디문제언어결과실행 시간메모리
128055ekrem정렬하기 (IOI15_sorting)C++98
74 / 100
1083 ms22520 KiB
#include "sorting.h" #include <bits/stdc++.h> #define st first #define nd second #define mp make_pair #define pb push_back #define sol (k+k) #define sag (k+k+1) #define orta ((bas+son)/2) #define coc g[node][i] #define EKLE 1 #define mod 1000000007 #define inf 1000000009 #define MAXN 1000005 using namespace std; typedef long long ll; typedef pair < int , int > ii; int n, m, f, a[MAXN], b[MAXN], x[MAXN], y[MAXN], yer[MAXN], p[MAXN], q[MAXN], s[MAXN]; bool dene(int son){ for(int i = 1; i <= n; i++)a[i] = s[i]; for(int i = 1; i <= n; i++) b[i] = i; for(int i = son; i >= 1; i--) swap(b[x[i]], b[y[i]]); for(int i = 1; i <= n; i++) yer[a[i]] = i; set < int > s; for(int i = 1; i <= n; i++){ if(a[i] != b[i]) s.insert(i); } int su = 1; for(int i = 1; i <= son; i++){ swap(a[x[i]], a[y[i]]); swap(yer[a[x[i]]], yer[a[y[i]]]); swap(b[x[i]], b[y[i]]); p[i] = x[i]; q[i] = y[i]; if(a[p[i]] == b[p[i]]) s.erase(p[i]); else s.insert(p[i]); if(a[q[i]] == b[q[i]]) s.erase(q[i]); else s.insert(q[i]); // cout << i << " ->\n"; // for(int i = 1; i <= n; i++)cout << a[i] << " ";cout << endl; // for(int i = 1; i <= n; i++)cout << b[i] << " ";cout << endl; if(s.empty()){ p[i] = q[i] = 1; continue; } int j = *s.begin(); p[i] = j; q[i] = yer[b[j]]; swap(a[p[i]], a[q[i]]); swap(yer[a[p[i]]], yer[a[q[i]]]); if(a[p[i]] == b[p[i]]) s.erase(p[i]); else s.insert(p[i]); if(a[q[i]] == b[q[i]]) s.erase(q[i]); else s.insert(q[i]); } // cout << son << " -> ";for(int i = 1; i <= n; i++)cout << a[i] << " ";cout << endl; for(int i = 1; i <= n; i++) if(a[i] != i) return 0; return 1; } int findSwapPairs(int nn, int S[], int M, int X[], int Y[], int P[], int Q[]) {n = nn;m = M; for(int i = 1; i <= n; i++){ s[i] = a[i] = S[i - 1] + EKLE; if(a[i] != i) f = 1; } if(!f)return 0; for(int i = 1; i <= m; i++){ x[i] = X[i - 1] + EKLE; y[i] = Y[i - 1] + EKLE; } int bas = 1, son = m; while(bas < son){ if(dene(orta)) son = orta; else bas = orta + 1; } dene(orta); for(int i = 1; i <= orta; i++){ P[i - 1] = p[i] - EKLE; Q[i - 1] = q[i] - EKLE; } return orta; }

컴파일 시 표준 에러 (stderr) 메시지

sorting.cpp: In function 'bool dene(int)':
sorting.cpp:36:14: warning: declaration of 's' shadows a global declaration [-Wshadow]
  set < int > s;
              ^
sorting.cpp:20:79: note: shadowed declaration is here
 int n, m, f, a[MAXN], b[MAXN], x[MAXN], y[MAXN], yer[MAXN], p[MAXN], q[MAXN], s[MAXN];
                                                                               ^
sorting.cpp:42:6: warning: unused variable 'su' [-Wunused-variable]
  int su = 1;
      ^~
#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...