제출 #1040171

#제출 시각아이디문제언어결과실행 시간메모리
1040171ZicrusSorting (IOI15_sorting)C++17
74 / 100
1024 ms21704 KiB
#pragma GCC optimize ("O3") #include <bits/stdc++.h> #include "sorting.h" using namespace std; typedef long long ll; int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P1[], int Q1[]) { vector<ll> h(N); for (int i = 0; i < N; i++) h[i] = S[i]; ll ooo = 0; for (int i = 0; i < N; i++) { if (h[i] != i) ooo++; } if (ooo == 0) return 0; ll res1 =0; ll low = 1, high = N; while (low < high) { ll g = (low + high) / 2; vector<int> P(M), Q(M); ll res = 0; vector<ll> s = h; vector<ll> order = s; vector<ll> revOrd(N), revS(N); for (int j = 0; j < g; j++) { swap(order[X[j]], order[Y[j]]); } for (int i = 0; i < N; i++) { revOrd[order[i]] = i; revS[s[i]] = i; } int id1 = -1; for (int i = 0; i < g; i++) { swap(s[X[i]], s[Y[i]]); swap(revS[s[X[i]]], revS[s[Y[i]]]); int firstOut = -1, id = -1; for (int j = id1+1; j < N; j++) { if (order[j] != j) { firstOut = order[id = j]; break; } } id1 = id; if (firstOut == -1) { P[res] = Q[res] = 0; res++; } else { ll iter = revOrd[id]; ll v = order[iter]; ll id1 = revS[firstOut]; ll id2 = revS[v]; swap(s[id1], s[id2]); swap(revS[s[id1]], revS[s[id2]]); swap(order[iter], order[id]); swap(revOrd[order[iter]], revOrd[order[id]]); P[res] = id1; Q[res] = id2; res++; } } bool ooo = 0; for (int i = g; i < N; i++) { if (s[i] != i) {ooo=1;break;} } if (ooo == 0) { res1 = res; high = res; for (int i = 0; i < res; i++) { P1[i] = P[i]; Q1[i] = Q[i]; } } else { low = g+1; } } return res1; }

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

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:44:44: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' may change value [-Wconversion]
   44 |                     firstOut = order[id = j];
      |                                            ^
sorting.cpp:57:20: warning: declaration of 'id1' shadows a previous local [-Wshadow]
   57 |                 ll id1 = revS[firstOut];
      |                    ^~~
sorting.cpp:37:13: note: shadowed declaration is here
   37 |         int id1 = -1;
      |             ^~~
sorting.cpp:63:26: warning: conversion from 'll' {aka 'long long int'} to '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} may change value [-Wconversion]
   63 |                 P[res] = id1;
      |                          ^~~
sorting.cpp:64:26: warning: conversion from 'll' {aka 'long long int'} to '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} may change value [-Wconversion]
   64 |                 Q[res] = id2;
      |                          ^~~
sorting.cpp:68:14: warning: declaration of 'ooo' shadows a previous local [-Wshadow]
   68 |         bool ooo = 0;
      |              ^~~
sorting.cpp:13:8: note: shadowed declaration is here
   13 |     ll ooo = 0;
      |        ^~~
sorting.cpp:69:22: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   69 |         for (int i = g; i < N; i++) {
      |                      ^
sorting.cpp:85:9: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   85 |  return res1;
      |         ^~~~
#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...