# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
258753 |
2020-08-06T13:53:27 Z |
atoiz |
Swap (BOI16_swap) |
C++14 |
|
60 ms |
5264 KB |
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
using namespace std;
const int MAXN = 200007;
int N, A[MAXN * 2], B[MAXN];
int getMin(int i)
{
if (B[i] == 0) return A[i];
int ans;
if ((i & 1)) {
if (B[i ^ 1] == 1) ans = A[i ^ 1];
else if (B[i ^ 1] == -1) ans = min(A[i ^ 1], getMin(i >> 1));
else ans = getMin(i >> 1);
} else {
ans = getMin(i >> 1);
}
if (B[i] == -1) ans = min(ans, A[i]);
return ans;
}
void retrieve(int i, int val)
{
if (B[i] == 0) {
assert(A[i] == val);
return;
}
if (A[i] == val) {
assert(B[i] == -1);
B[i] = 0;
return;
}
B[i] = 1;
if ((i & 1)) {
if (B[i ^ 1] == 1) assert(A[i ^ 1] == val);
else if (B[i ^ 1] == -1) {
B[i ^ 1] = (A[i ^ 1] == val);
if (!B[i ^ 1]) retrieve(i >> 1, val);
}
else retrieve(i >> 1, val);
} else retrieve(i >> 1, val);
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> N;
for (int i = 1; i <= N; ++i) cin >> A[i];
for (int i = N + 1; i <= 2 * N + 1; ++i) A[i] = MAXN;
for (int i = 1; i <= N; ++i) {
int cur = getMin(i);
int minVal = min(cur, min(A[i << 1], A[i << 1 | 1]));
if (cur == minVal) retrieve(i, cur);
else if (A[i << 1] == minVal) {
B[i << 1] = 1;
} else {
B[i << 1] = -1, B[i << 1 | 1] = 1;
}
}
for (int i = 2; i <= N; ++i) if (B[i]) swap(A[i >> 1], A[i]);
for (int i = 1; i <= N; ++i) cout << A[i] << ' '; cout << endl;
}
Compilation message
swap.cpp: In function 'int main()':
swap.cpp:69:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
for (int i = 1; i <= N; ++i) cout << A[i] << ' '; cout << endl;
^~~
swap.cpp:69:52: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
for (int i = 1; i <= N; ++i) cout << A[i] << ' '; cout << endl;
^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
400 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
400 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
400 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
14 ms |
1548 KB |
Output is correct |
17 |
Correct |
12 ms |
1536 KB |
Output is correct |
18 |
Correct |
16 ms |
1536 KB |
Output is correct |
19 |
Correct |
15 ms |
1536 KB |
Output is correct |
20 |
Correct |
14 ms |
1536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
400 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
14 ms |
1548 KB |
Output is correct |
17 |
Correct |
12 ms |
1536 KB |
Output is correct |
18 |
Correct |
16 ms |
1536 KB |
Output is correct |
19 |
Correct |
15 ms |
1536 KB |
Output is correct |
20 |
Correct |
14 ms |
1536 KB |
Output is correct |
21 |
Correct |
56 ms |
5264 KB |
Output is correct |
22 |
Correct |
48 ms |
5244 KB |
Output is correct |
23 |
Correct |
46 ms |
5240 KB |
Output is correct |
24 |
Correct |
59 ms |
5240 KB |
Output is correct |
25 |
Correct |
60 ms |
5240 KB |
Output is correct |