# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
974065 | 2024-05-02T17:37:11 Z | PagodePaiva | Sorting (IOI15_sorting) | C++17 | 1 ms | 600 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++){ inv[v[i]] = i; invst[st[i]] = i; } for(int at = 0, i = 0;i <= res;i++){ while(at < n){ if(st[at] == v[at]) at++; else break; } if(at == n) return i; swap(v[x[i]], v[y[i]]); swap(inv[v[x[i]]], inv[v[y[i]]]); swap(st[x[i]], st[y[i]]); swap(invst[st[x[i]]], invst[st[y[i]]]); p[i] = at; q[i] = invst[v[at]]; swap(st[at], st[invst[v[at]]]); swap(invst[st[p[i]]], invst[st[q[i]]]); at++; } return res+1; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 1 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 1 ms | 348 KB | Output is correct |
7 | Correct | 1 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 1 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 1 ms | 348 KB | Output is correct |
7 | Correct | 1 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 1 ms | 364 KB | Output is correct |
10 | Correct | 0 ms | 600 KB | Output is correct |
11 | Correct | 0 ms | 348 KB | Output is correct |
12 | Correct | 0 ms | 344 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Incorrect | 0 ms | 348 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 1 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 1 ms | 348 KB | Output is correct |
7 | Correct | 1 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 1 ms | 364 KB | Output is correct |
10 | Correct | 0 ms | 600 KB | Output is correct |
11 | Correct | 0 ms | 348 KB | Output is correct |
12 | Correct | 0 ms | 344 KB | Output is correct |
13 | Correct | 1 ms | 348 KB | Output is correct |
14 | Incorrect | 0 ms | 348 KB | Output isn't correct |
15 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 344 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 344 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |