제출 #223564

#제출 시각아이디문제언어결과실행 시간메모리
223564davitmarg정렬하기 (IOI15_sorting)C++17
0 / 100
6 ms640 KiB
/*DavitMarg*/ #include <iostream> #include <cstdio> #include <algorithm> #include <cmath> #include <vector> #include <string> #include <cstring> #include <list> #include <map> #include <unordered_map> #include <set> #include <unordered_set> #include <queue> #include <iomanip> #include <bitset> #include <stack> #include <cassert> #include <iterator> #include <fstream> #define mod 1000000007ll #define LL long long #define LD long double #define MP make_pair #define PB push_back #define all(v) v.begin(), v.end() using namespace std; #ifndef death #include "sorting.h" #endif const int N = 200005; int n, q, a[N], b[N], s[N], x[30 * N], y[30 * N]; int pos[N], posa[N]; vector<pair<int, int>> ans; bool check(int k) { ans.clear(); for (int i = 0; i < n; i++) { a[i] = i; b[i] = s[i]; } for (int i = 0; i < k; i++) { swap(a[x[i]], a[y[i]]); swap(b[x[i]], b[y[i]]); } for (int i = 0; i < n; i++) { posa[a[i]] = i; pos[s[i]] = a[i]; b[a[i]] = s[i]; } for (int i = 0; i < n; i++) { if (b[i] == i) continue; //swap pos[b[i]] pos[i]; int x= pos[b[i]], y=pos[i]; ans.push_back(MP(posa[pos[b[i]]], posa[pos[i]])); swap(b[x], b[y]); swap(pos[b[x]], pos[b[y]]); } while (ans.size() < k) ans.PB(MP(0, 0)); return(ans.size() <= k); } int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { n = N; for (int i = 0; i < n; i++) s[i] = S[i]; q = M; for (int i = 0; i < q; i++) { x[i] = X[i]; y[i] = Y[i]; } int l=0, r=n-1, m, c; /*while (l <= r) { m = (l + r) / 2; if (check(m)) { c = m; r = m - 1; } else l = m + 1; }*/ /*for (int i = n; i >= 0; i--) if (check(i)) c = i;*/ c = 3; check(c); for (int i = 0; i < ans.size(); i++) { P[i] = ans[i].first; Q[i] = ans[i].second; } return ans.size(); } #ifdef death int main() { int N, S[102], M, X[102], Y[102], P[102], Q[102], R; cin >> N; for (int i = 0; i < N; i++) cin >> S[i]; cin >> M; for (int i = 0; i < M; i++) cin >> X[i] >> Y[i]; R = findSwapPairs(N, S, M, X, Y, P, Q); cout << endl; cout << R << endl; for (int i = 0; i < R; i++) cout << P[i] << " : " << Q[i] << endl; for (int i = 0; i < R; i++) { swap(S[P[i]], S[Q[i]]); swap(S[X[i]], S[Y[i]]); } for (int i = 0; i < N; i++) cout << S[i] << ", "; cout << endl; return 0; } #endif /* 5 4 3 2 1 0 6 0 1 1 2 2 3 3 4 0 1 1 2 5 2 0 1 3 4 3 0 1 0 1 0 1 */

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

sorting.cpp: In function 'bool check(int)':
sorting.cpp:62:7: warning: declaration of 'x' shadows a global declaration [-Wshadow]
   int x= pos[b[i]], y=pos[i];
       ^
sorting.cpp:34:29: note: shadowed declaration is here
 int n, q, a[N], b[N], s[N], x[30 * N], y[30 * N];
                             ^
sorting.cpp:62:21: warning: declaration of 'y' shadows a global declaration [-Wshadow]
   int x= pos[b[i]], y=pos[i];
                     ^
sorting.cpp:34:40: note: shadowed declaration is here
 int n, q, a[N], b[N], s[N], x[30 * N], y[30 * N];
                                        ^
sorting.cpp:67:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while (ans.size() < k)
         ~~~~~~~~~~~^~~
sorting.cpp:69:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  return(ans.size() <= k);
         ~~~~~~~~~~~^~~~
sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:73:76: warning: declaration of 'N' shadows a global declaration [-Wshadow]
 int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[])
                                                                            ^
sorting.cpp:32:11: note: shadowed declaration is here
 const int N = 200005;
           ^
sorting.cpp:102:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < ans.size(); i++)
                  ~~^~~~~~~~~~~~
sorting.cpp:107:17: warning: conversion to 'int' from 'std::vector<std::pair<int, int> >::size_type {aka long unsigned int}' may alter its value [-Wconversion]
  return ans.size();
         ~~~~~~~~^~
sorting.cpp:85:6: warning: unused variable 'l' [-Wunused-variable]
  int l=0, r=n-1, m, c;
      ^
sorting.cpp:85:11: warning: unused variable 'r' [-Wunused-variable]
  int l=0, r=n-1, m, c;
           ^
sorting.cpp:85:18: warning: unused variable 'm' [-Wunused-variable]
  int l=0, r=n-1, m, c;
                  ^
#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...