Submission #1039943

#TimeUsernameProblemLanguageResultExecution timeMemory
1039943ZicrusSorting (IOI15_sorting)C++17
36 / 100
1093 ms604 KiB
#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 P[], int Q[]) { 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; for (int g = 0; g <= M; g++) { ll res = 0; vector<ll> s = h; for (int i = 0; i < g; i++) { swap(s[X[i]], s[Y[i]]); vector<ll> order = s; for (int j = i+1; j < M; j++) { swap(order[X[j]], order[Y[j]]); } int firstOut = -1, id = -1; for (int j = 0; j < N; j++) { if (order[j] != j) { firstOut = order[id = j]; break; } } if (firstOut == -1) { P[res] = Q[res] = 0; res++; } else { ll v = *find(order.begin(), order.end(), id); ll id1 = find(s.begin(), s.end(), firstOut) - s.begin(); ll id2 = find(s.begin(), s.end(), v) - s.begin(); swap(s[id1], s[id2]); P[res] = id1; Q[res] = id2; res++; } firstOut = -1; for (int j = 0; j < N; j++) { if (s[j] != j) { firstOut = s[j]; break; } } if (firstOut == -1) return res; } ll ooo = 0; for (int i = 0; i < N; i++) { if (s[i] != i) ooo++; } if (ooo == 0) return res; } return 0; }

Compilation message (stderr)

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:29: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]
   29 |                     firstOut = order[id = j];
      |                                            ^
sorting.cpp:43:26: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   43 |                 P[res] = id1;
      |                          ^~~
sorting.cpp:44:26: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   44 |                 Q[res] = id2;
      |                          ^~~
sorting.cpp:51:35: 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]
   51 |                     firstOut = s[j];
      |                                   ^
sorting.cpp:55:40: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   55 |             if (firstOut == -1) return res;
      |                                        ^~~
sorting.cpp:57:12: warning: declaration of 'ooo' shadows a previous local [-Wshadow]
   57 |         ll ooo = 0;
      |            ^~~
sorting.cpp:11:8: note: shadowed declaration is here
   11 |     ll ooo = 0;
      |        ^~~
sorting.cpp:61:30: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   61 |         if (ooo == 0) return res;
      |                              ^~~
#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...