/*
doing virtual contest
start: 10:00
finish: 14:00
*/
#include <bits/stdc++.h>
using namespace std;
int query(int s, int t);
void answer(int i, int a);
#ifndef EVAL
const int N_ = 5007;
int n_;
int a_[N_], ans_[N_];
int query(int s, int t) {
int mn = n_, mx = 1;
for (int i = s; i <= t; ++i) {
mn = min(mn, a_[i]);
mx = max(mx, a_[i]);
}
return mx - mn;
}
void answer(int i, int a) {
if (i < 1 || i > n_) {
cout << "incorrect index " << i << endl;
exit(0);
}
if (ans_[i] != -1) {
cout << i << " used twice" << endl;
exit(0);
}
ans_[i] = a;
}
void check_ans() {
bool corr = 1;
for (int i = 1; i <= n_; ++i) corr &= a_[i] == ans_[i];
if (!corr) {
cout << "incorrect" << endl;
for (int i = 1; i <= n_; ++i) cout << a_[i] << " ";
cout << endl;
for (int i = 1; i <= n_; ++i) cout << ans_[i] << " ";
cout << endl;
} else {
cout << "correct\n";
}
}
void init(int n, vector<int> a) {
n_ = n;
for (int i = 1; i <= n; ++i) {
a_[i] = a[i - 1];
ans_[i] = -1;
}
}
#endif
void solve(int n) {
vector<int> a(n + 1, -1);
a[1] = 0;
if (2 <= n) a[2] = query(1, 2);
for (int i = 3; i <= n; ++i) {
int x = a[i - 2], y = a[i - 1];
int d = query(i - 1, i);
if (abs(x - y) + d == query(i - 2, i)) {
a[i] = y < x ? y - d : y + d;
} else {
a[i] = y < x ? y + d : y - d;
}
}
int mn = (int)1e9;
for (int i = 1; i <= n; ++i) mn = min(mn, a[i]);
for (int i = 1; i <= n; ++i) a[i] += -mn + 1;
int pos1 = -1, posn = -1;
for (int i = 1; i <= n; ++i) {
if (a[i] == 1) pos1 = i;
if (a[i] == n) posn = i;
}
if (pos1 > posn) {
for (int i = 1; i <= n; ++i) a[i] = n - a[i] + 1;
}
for (int i = 1; i <= n; ++i) answer(i, a[i]);
}
#ifndef EVAL
int main() {
freopen("input.txt", "r", stdin);
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; ++i) cin >> a[i];
init(n, a);
solve(n);
check_ans();
return 0;
}
#endif
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
3 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
2 ms |
364 KB |
Output is correct |
10 |
Correct |
3 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
364 KB |
Output is correct |
12 |
Correct |
3 ms |
364 KB |
Output is correct |
13 |
Correct |
2 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
3 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
2 ms |
364 KB |
Output is correct |
10 |
Correct |
3 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
364 KB |
Output is correct |
12 |
Correct |
3 ms |
364 KB |
Output is correct |
13 |
Correct |
2 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
364 KB |
Output is correct |
16 |
Correct |
6 ms |
364 KB |
Output is correct |
17 |
Correct |
13 ms |
364 KB |
Output is correct |
18 |
Correct |
20 ms |
364 KB |
Output is correct |
19 |
Correct |
23 ms |
364 KB |
Output is correct |
20 |
Correct |
24 ms |
380 KB |
Output is correct |
21 |
Correct |
11 ms |
380 KB |
Output is correct |
22 |
Correct |
26 ms |
364 KB |
Output is correct |
23 |
Correct |
14 ms |
364 KB |
Output is correct |
24 |
Correct |
25 ms |
364 KB |
Output is correct |
25 |
Correct |
25 ms |
364 KB |
Output is correct |
26 |
Correct |
21 ms |
492 KB |
Output is correct |
27 |
Correct |
17 ms |
364 KB |
Output is correct |
28 |
Correct |
12 ms |
380 KB |
Output is correct |
29 |
Correct |
17 ms |
492 KB |
Output is correct |
30 |
Correct |
17 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
3 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
2 ms |
364 KB |
Output is correct |
10 |
Correct |
3 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
364 KB |
Output is correct |
12 |
Correct |
3 ms |
364 KB |
Output is correct |
13 |
Correct |
2 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
364 KB |
Output is correct |
16 |
Correct |
6 ms |
364 KB |
Output is correct |
17 |
Correct |
13 ms |
364 KB |
Output is correct |
18 |
Correct |
20 ms |
364 KB |
Output is correct |
19 |
Correct |
23 ms |
364 KB |
Output is correct |
20 |
Correct |
24 ms |
380 KB |
Output is correct |
21 |
Correct |
11 ms |
380 KB |
Output is correct |
22 |
Correct |
26 ms |
364 KB |
Output is correct |
23 |
Correct |
14 ms |
364 KB |
Output is correct |
24 |
Correct |
25 ms |
364 KB |
Output is correct |
25 |
Correct |
25 ms |
364 KB |
Output is correct |
26 |
Correct |
21 ms |
492 KB |
Output is correct |
27 |
Correct |
17 ms |
364 KB |
Output is correct |
28 |
Correct |
12 ms |
380 KB |
Output is correct |
29 |
Correct |
17 ms |
492 KB |
Output is correct |
30 |
Correct |
17 ms |
364 KB |
Output is correct |
31 |
Correct |
51 ms |
364 KB |
Output is correct |
32 |
Correct |
47 ms |
620 KB |
Output is correct |
33 |
Correct |
111 ms |
392 KB |
Output is correct |
34 |
Correct |
95 ms |
396 KB |
Output is correct |
35 |
Correct |
88 ms |
364 KB |
Output is correct |
36 |
Correct |
86 ms |
364 KB |
Output is correct |
37 |
Correct |
111 ms |
492 KB |
Output is correct |
38 |
Correct |
83 ms |
364 KB |
Output is correct |
39 |
Correct |
104 ms |
492 KB |
Output is correct |
40 |
Correct |
91 ms |
364 KB |
Output is correct |
41 |
Correct |
52 ms |
396 KB |
Output is correct |
42 |
Correct |
77 ms |
364 KB |
Output is correct |
43 |
Correct |
53 ms |
396 KB |
Output is correct |
44 |
Correct |
130 ms |
364 KB |
Output is correct |
45 |
Correct |
93 ms |
364 KB |
Output is correct |
46 |
Correct |
86 ms |
364 KB |
Output is correct |
47 |
Correct |
80 ms |
364 KB |
Output is correct |
48 |
Correct |
118 ms |
492 KB |
Output is correct |
49 |
Correct |
74 ms |
492 KB |
Output is correct |
50 |
Correct |
115 ms |
492 KB |
Output is correct |
51 |
Correct |
84 ms |
396 KB |
Output is correct |
52 |
Correct |
91 ms |
492 KB |
Output is correct |
53 |
Correct |
89 ms |
364 KB |
Output is correct |
54 |
Correct |
82 ms |
396 KB |
Output is correct |
55 |
Correct |
102 ms |
492 KB |
Output is correct |
56 |
Correct |
113 ms |
492 KB |
Output is correct |
57 |
Correct |
118 ms |
492 KB |
Output is correct |
58 |
Correct |
121 ms |
364 KB |
Output is correct |
59 |
Correct |
92 ms |
364 KB |
Output is correct |
60 |
Correct |
119 ms |
364 KB |
Output is correct |