Submission #633802

#TimeUsernameProblemLanguageResultExecution timeMemory
633802devvopsXor Sort (eJOI20_xorsort)C++17
25 / 100
105 ms18432 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define F first #define S second #define int long long #define ull unsigned long long #define all(x) x.begin(), x.end() #define speed ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL) #define file freopen("palindrome.in", "r", stdin), freopen("palindrome.out", "w", stdout); const int N = (int) 5 * 1e5, inf = INT_MAX; int a[2000], b[2000]; main() { speed; int n, S; cin >> n >> S; vector<pair<int, int>> v; v.pb({0, 0}); for(int i = 1; i <= n; i++){ cin >> a[i]; b[i] = a[i]; } sort(b + 1, b + 1 + n); for(int i = n; i >= 1; i--){ if(b[i] == a[i]){ continue; } int x; for(int j = 1; j <= n; j++){ if(a[j] == b[i]){ x = j; break; } } while(x != i){ v.pb({x + 1, x}); v.pb({x, x + 1}); v.pb({x + 1, x}); swap(a[x], a[x + 1]); x++; } } cout << v.size() - 1 << "\n"; for(int i = 1; i < v.size(); i++){ cout << v[i].F << " " << v[i].S << '\n'; } }

Compilation message (stderr)

xorsort.cpp:13:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   13 | main() {
      | ^~~~
xorsort.cpp: In function 'int main()':
xorsort.cpp:44:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |     for(int i = 1; i < v.size(); i++){
      |                    ~~^~~~~~~~~~
xorsort.cpp:28:10: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
   28 |      int x;
      |          ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...