# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
974071 | 2024-05-02T17:50:46 Z | PagodePaiva | Sorting (IOI15_sorting) | C++17 | 1000 ms | 78848 KB |
#include<bits/stdc++.h> #include "sorting.h" using namespace std; int findSwapPairs(int n, int st[], int m, int x[], int y[], int p[], int q[]) { bool aux = true; for(int i = 0;i < n;i++){ if(st[i] != i) aux = false; } if(aux){ return 0; } int l = 0, r = m-1, res = 0; while(l <= r){ int mid = (l+r)/2; vector <int> v; for(int i = 0;i < n;i++){ v.push_back(i); } for(int i = mid;i >= 0;i--){ swap(v[x[i]], v[y[i]]); } int pai[n]; for(int i = 0;i < n;i++){ pai[v[i]] = st[i]; } int resp = 0; int mark[n]; memset(mark, 0, sizeof mark); for(int i = 0;i < n;i++){ if(mark[i]) continue; int x = i; while(!mark[x]){ mark[x] = 1; resp++; x = pai[x]; } resp--; } if(resp <= mid+1){ res = mid; r = mid-1; } else{ l = mid+1; } } vector <int> v; for(int i = 0;i < n;i++){ v.push_back(i); } int inv[n+1], invst[n+1]; for(int i = res;i >= 0;i--){ swap(v[x[i]], v[y[i]]); } for(int i = 0;i < n;i++){ invst[st[i]] = i; } cout << res << '\n'; for(int at = 0, i = 0;i <= res;i++){ while(at < n){ if(st[at] == v[at]) at++; else break; } if(at == n) return res+1; swap(v[x[i]], v[y[i]]); swap(st[x[i]], st[y[i]]); swap(invst[st[x[i]]], invst[st[y[i]]]); while(at < n){ if(st[at] == v[at]) at++; else break; } if(at == n) return res+1; for(int i = 0;i < n;i++){ cout << i << ' ' << st[i] << ' ' << invst[st[i]] << '\n'; } cout << "\n"; p[i] = at; q[i] = invst[v[at]]; swap(st[p[i]], st[q[i]]); swap(invst[st[p[i]]], invst[st[q[i]]]); for(int i = 0;i < n;i++){ cout << i << ' ' << st[i]<< ' ' << invst[st[i]] << '\n'; } cout << '\n'; at++; if(at == n) return res+1; } return res+1; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Incorrect | 0 ms | 348 KB | Hacked |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Incorrect | 0 ms | 348 KB | Hacked |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Incorrect | 2 ms | 344 KB | Expected EOLN |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Incorrect | 0 ms | 348 KB | Hacked |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1082 ms | 78848 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1082 ms | 78848 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |