# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
568619 |
2022-05-25T20:08:37 Z |
urosk |
Sorting (IOI15_sorting) |
C++14 |
|
1 ms |
468 KB |
#include "sorting.h"
#define here cerr<<"===========================================\n"
#include <bits/stdc++.h>
#define ld double
#define ll int
#define ull unsigned long long
#define llinf 100000000000000000LL // 10^17
#define iinf 2000000000 // 2*10^9
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) int(a.size())
#define all(a) a.begin(),a.end()
#define ceri(a,l,r) {for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
using namespace std;
#define maxn 105
ll n,m;
ll a[maxn];
ll p[maxn];
bool sorted(){
for(ll i = 1;i<n;i++) if(a[i]>a[i+1]) return 0;
return 1;
}
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
n = N;
m = M;
for(ll i = 1;i<=n;i++) a[i] = S[i-1]+1;
for(ll i = 1;i<=n;i++) p[a[i]] = i;
ll sum = 0;
for(ll i = 0;i<m;i++) sum+=X[i] + Y[i];
ceri(a,1,n);
if(sum==0){
for(ll i = 1;i<=n;i++){
if(sorted()) return i-1;
P[i-1] = i-1;
Q[i-1] = p[i]-1;
ll x = a[i];
a[p[i]] = a[i];
a[i] = i;
swap(p[i],p[x]);
}
return n;
}
if(sorted()) return 0;
ll i = 1;
P[i-1] = i-1;
Q[i-1] = p[i]-1;
ll x = a[i];
a[p[i]] = a[i];
a[i] = i;
swap(p[i],p[x]);
swap(p[a[0]],p[a[1]]);
swap(a[0],a[1]);
if(sorted()) return 1;
i = 2;
P[i-1] = 0;
Q[i-1] = p[i]-1;
x = a[0];
a[p[i]] = a[0];
a[0] = 1;
swap(p[i],p[x]);
swap(p[a[0]],p[a[1]]);
swap(a[0],a[1]);
if(sorted()) return 2;
for(ll i = 3;i<=n;i++){
if(sorted()) return i-1;
P[i-1] = i-1;
Q[i-1] = p[i]-1;
ll x = a[i];
a[p[i]] = a[i];
a[i] = i;
swap(p[i],p[x]);
swap(a[0],a[1]);
}
if(sorted()) return n;
P[n] = 0;
Q[n] = 0;
return n+1;
}
Compilation message
sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:72:12: warning: declaration of 'i' shadows a previous local [-Wshadow]
72 | for(ll i = 3;i<=n;i++){
| ^
sorting.cpp:52:8: note: shadowed declaration is here
52 | ll i = 1;
| ^
sorting.cpp:76:12: warning: declaration of 'x' shadows a previous local [-Wshadow]
76 | ll x = a[i];
| ^
sorting.cpp:55:8: note: shadowed declaration is here
55 | ll x = a[i];
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
312 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
312 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |