# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
395449 |
2021-04-28T11:15:31 Z |
rocks03 |
Sorting (IOI15_sorting) |
C++14 |
|
1000 ms |
460 KB |
//#pragma GCC target("avx2")
//#pragma GCC optimization("O3")
//#pragma GCC optimization("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define pb push_back
#define SZ(x) ((int)(x).size())
#define all(x) x.begin(), x.end()
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int findSwapPairs(int N, int B[], int M, int X[], int Y[], int P[], int Q[]){
int np[M], nq[M];
vector<int> a, pos;
set<int> st;
auto swappa = [&](int i, int j){
auto it = st.find(a[i]);
if(it != st.end()) st.erase(it);
it = st.find(a[j]);
if(it != st.end()) st.erase(it);
swap(pos[a[i]], pos[a[j]]);
swap(a[i], a[j]);
if(a[i] != i) st.insert(a[i]);
if(a[j] != j) st.insert(a[j]);
};
auto random_sol = [&](){
int ans = 0;
while(SZ(st) && ans <= M){
int i = X[ans], j = Y[ans];
swappa(i, j);
if(SZ(st) == 0){
np[ans] = 0;
nq[ans] = 0;
ans++; break;
}
int x = rng() % N;
auto it = st.lower_bound(x);
if(it == st.end()) it--;
x = *it;
i = pos[x], j = x;
np[ans] = i; nq[ans] = j;
ans++;
swappa(i, j);
}
return ans;
};
while(true){
pos = a = vector<int>(N);
rep(i, 0, N){
a[i] = B[i];
pos[a[i]] = i;
}
st.clear();
rep(i, 0, N){
if(a[i] != i) st.insert(i);
}
int ans = random_sol();
if(ans > M) continue;
rep(i, 0, N) a[i] = B[i];
rep(i, 0, ans){
swap(a[X[i]], a[Y[i]]);
swap(a[np[i]], a[nq[i]]);
}
rep(i, 0, ans){
if(a[i] != i){
ans = -1; break;
}
}
if(ans != -1){
rep(i, 0, N){
P[i] = np[i];
Q[i] = nq[i];
}
return ans;
}
}
}
Compilation message
sorting.cpp: In lambda function:
sorting.cpp:42:27: warning: conversion from 'std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>::result_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
42 | int x = rng() % N;
| ~~~~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
308 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
1 ms |
308 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
308 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Incorrect |
1 ms |
308 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1077 ms |
460 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1077 ms |
460 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |