Task: | Polygonal Chain |
Sender: | voventa |
Submission time: | 2021-02-16 23:02:39 +0200 |
Language: | C++ (C++17) |
Status: | READY |
Result: | 15 |
group | verdict | score |
---|---|---|
#1 | WRONG ANSWER | 0 |
#2 | WRONG ANSWER | 0 |
#3 | ACCEPTED | 15 |
#4 | WRONG ANSWER | 0 |
#5 | WRONG ANSWER | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.01 s | 1, 2, 4, 5 | details |
#2 | WRONG ANSWER | 0.01 s | 1, 2, 4, 5 | details |
#3 | ACCEPTED | 0.01 s | 1, 2, 4, 5 | details |
#4 | ACCEPTED | 0.01 s | 1, 2, 4, 5 | details |
#5 | ACCEPTED | 0.01 s | 1, 2, 4, 5 | details |
#6 | WRONG ANSWER | 0.01 s | 2, 4, 5 | details |
#7 | ACCEPTED | 0.01 s | 2, 4, 5 | details |
#8 | ACCEPTED | 0.01 s | 2, 4, 5 | details |
#9 | WRONG ANSWER | 0.01 s | 2, 4, 5 | details |
#10 | ACCEPTED | 0.01 s | 2, 4, 5 | details |
#11 | WRONG ANSWER | 0.01 s | 4, 5 | details |
#12 | TIME LIMIT EXCEEDED | -- | 5 | details |
#13 | ACCEPTED | 0.01 s | 3, 4, 5 | details |
#14 | ACCEPTED | 0.01 s | 3, 4, 5 | details |
#15 | ACCEPTED | 0.01 s | 1, 2, 4, 5 | details |
#16 | WRONG ANSWER | 0.01 s | 4, 5 | details |
#17 | WRONG ANSWER | 0.01 s | 4, 5 | details |
#18 | TIME LIMIT EXCEEDED | -- | 5 | details |
#19 | ACCEPTED | 0.01 s | 1, 2, 4, 5 | details |
#20 | WRONG ANSWER | 0.01 s | 2, 4, 5 | details |
#21 | ACCEPTED | 0.01 s | 2, 4, 5 | details |
#22 | WRONG ANSWER | 0.01 s | 2, 4, 5 | details |
#23 | WRONG ANSWER | 0.01 s | 4, 5 | details |
#24 | WRONG ANSWER | 0.01 s | 4, 5 | details |
#25 | ACCEPTED | 0.01 s | 4, 5 | details |
#26 | ACCEPTED | 0.03 s | 5 | details |
#27 | WRONG ANSWER | 0.04 s | 5 | details |
#28 | WRONG ANSWER | 0.05 s | 5 | details |
#29 | WRONG ANSWER | 0.05 s | 5 | details |
#30 | ACCEPTED | 0.01 s | 1, 2, 4, 5 | details |
Code
#include <bits/stdc++.h> #define X first #define Y second #define sz(a) (int)a.size() #define pb push_back //#define int long long using namespace std; typedef long long ll; void solve(); signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; //cin >> t; while (t--) solve(); return 0; } int a[100010]; pair <int, int> xx[100010]; string s; struct node { int ind; char dl, dr; }; vector <vector <node>> v; vector <int> ans, ans2; void solve() { int n, l = 0, r; cin >> n; for (int i = 0; i < n; ++i) { cin >> a[i]; if (i == 0) { r = a[i]; } else { l = r; if (i % 2 == 1) r = l - a[i]; else r = l + a[i]; } xx[i] = {l, r}; } cin >> s; int A, B, C; for (int i = 0; i < n; ++i) { if (i == n - 1) { v.pb({{i, s[i - 1], '#'}}); } else if (i == 0) { v.pb({{i, '#', s[i]}}); } else { v.pb({{i, s[i - 1], s[i]}}); } while (sz(v) > 2) { char c1 = v[sz(v) - 3].back().dr, c2 = v[sz(v) - 2].back().dr; A = max({abs(xx[v[sz(v) - 3][0].ind].X - xx[v[sz(v) - 3].back().ind].Y), abs(xx[v[sz(v) - 3][0].ind].Y - xx[v[sz(v) - 3].back().ind].X), abs(xx[v[sz(v) - 3][0].ind].X - xx[v[sz(v) - 3].back().ind].X), abs(xx[v[sz(v) - 3][0].ind].Y - xx[v[sz(v) - 3].back().ind].Y)}); B = max({abs(xx[v[sz(v) - 2][0].ind].X - xx[v[sz(v) - 2].back().ind].Y), abs(xx[v[sz(v) - 2][0].ind].Y - xx[v[sz(v) - 2].back().ind].X), abs(xx[v[sz(v) - 2][0].ind].X - xx[v[sz(v) - 2].back().ind].X), abs(xx[v[sz(v) - 2][0].ind].Y - xx[v[sz(v) - 2].back().ind].Y)}); C = max({abs(xx[v[sz(v) - 1][0].ind].X - xx[v[sz(v) - 1].back().ind].Y), abs(xx[v[sz(v) - 1][0].ind].Y - xx[v[sz(v) - 1].back().ind].X), abs(xx[v[sz(v) - 1][0].ind].X - xx[v[sz(v) - 1].back().ind].X), abs(xx[v[sz(v) - 1][0].ind].Y - xx[v[sz(v) - 1].back().ind].Y)}); if ((A < B && B < C) || (A < B && B > C) || (A > B && B > C) || (A == B && B > C) || (A < B && B == C)) { break; } if ((A == B && B == C) || (A > B && B == C) ) { if (c1 != c2) { cout << "NO"; return; } else { if (c1 == s[i] || i == n - 1) { for (auto i : v[sz(v) - 2]) { v[sz(v) - 3].pb(i); } for (auto i : v[sz(v) - 1]) { v[sz(v) - 3].pb(i); } v.pop_back(); v.pop_back(); continue; } else break; } } if (c1 != c2) { cout << "NO"; return; } for (auto i : v[sz(v) - 2]) { v[sz(v) - 3].pb(i); } for (auto i : v[sz(v) - 1]) { v[sz(v) - 3].pb(i); } v.pop_back(); v.pop_back(); } } int t = -1; for (int i = 1; i < sz(v); ++i) { int t1 = max({abs(xx[v[i - 1][0].ind].X - xx[v[i - 1].back().ind].Y), abs(xx[v[i - 1][0].ind].Y - xx[v[i - 1].back().ind].X), abs(xx[v[i - 1][0].ind].X - xx[v[i - 1].back().ind].X), abs(xx[v[i - 1][0].ind].Y - xx[v[i - 1].back().ind].Y)}); int t2 = max({abs(xx[v[i][0].ind].X - xx[v[i].back().ind].Y), abs(xx[v[i][0].ind].Y - xx[v[i].back().ind].X), abs(xx[v[i][0].ind].X - xx[v[i].back().ind].X), abs(xx[v[i][0].ind].Y - xx[v[i].back().ind].Y)}); if (t1 >= t2) { t = i; break; } } if (t == -1) { for (auto i : v) { for (auto j : i) { if (j.dr == j.dl) { ans.pb(1); } else { ans.pb(sz(ans) + 1); } } } } else { for (int i = 0; i < t; ++i) { for (auto j : v[i]) { if (j.dr == j.dl) { ans.pb(1); } else { ans.pb(sz(ans) + 1); } } } } if (t != -1) { for (int i = sz(v) - 1; i >= t; --i) { for (int j = sz(v[i]) - 1; j >= 0; --j) { if (v[i][j].dr == v[i][j].dl) { ans2.pb(1); } else { ans2.pb(sz(ans2) + 1); } } } } if (sz(ans) > 0) ans.pop_back(); if (sz(ans2) > 0) ans2.pop_back(); reverse(ans2.begin(), ans2.end()); cout << "YES\n"; for (auto i : ans) { cout << i << " "; } if (t != -1) { cout << 1000000 << ' '; for (auto i : ans2) { cout << i << " "; } } return; } /*/ A = max({abs(xx[v[sz(v) - 3][0].ind].X - xx[v[sz(v) - 3].back().ind].Y), abs(xx[v[sz(v) - 3][0].ind].Y - xx[v[sz(v) - 3].back().ind].X), abs(xx[v[sz(v) - 3][0].ind].X - xx[v[sz(v) - 3].back().ind].X), abs(xx[v[sz(v) - 3][0].ind].Y - xx[v[sz(v) - 3].back().ind].Y)}); B = max({abs(xx[v[sz(v) - 2][0].ind].X - xx[v[sz(v) - 2].back().ind].Y), abs(xx[v[sz(v) - 2][0].ind].Y - xx[v[sz(v) - 2].back().ind].X), abs(xx[v[sz(v) - 2][0].ind].X - xx[v[sz(v) - 2].back().ind].X), abs(xx[v[sz(v) - 2][0].ind].Y - xx[v[sz(v) - 2].back().ind].Y)}); C = max({abs(xx[v[sz(v) - 1][0].ind].X - xx[v[sz(v) - 1].back().ind].Y), abs(xx[v[sz(v) - 1][0].ind].Y - xx[v[sz(v) - 1].back().ind].X), abs(xx[v[sz(v) - 1][0].ind].X - xx[v[sz(v) - 1].back().ind].X), abs(xx[v[sz(v) - 1][0].ind].Y - xx[v[sz(v) - 1].back().ind].Y)}); /*/
Test details
Test 1
Group: 1, 2, 4, 5
Verdict: ACCEPTED
input |
---|
2 2 10 D |
correct output |
---|
YES 1 |
user output |
---|
YES 1 |
Test 2
Group: 1, 2, 4, 5
Verdict: WRONG ANSWER
input |
---|
8 5 8 7 5 6 5 3 4 DUUUDDD |
correct output |
---|
YES 1 5 1 1 3 1 1 |
user output |
---|
YES 1 1000000 1 4 1 1 1 |
Test 3
Group: 1, 2, 4, 5
Verdict: ACCEPTED
input |
---|
8 9 8 8 10 10 8 9 10 DDDUUUD |
correct output |
---|
YES 1 1 1 4 1 1 7 |
user output |
---|
YES 1 1 1 4 1 1 1000000 |
Test 4
Group: 1, 2, 4, 5
Verdict: ACCEPTED
input |
---|
8 9 10 8 8 9 9 7 8 DDDDUUU |
correct output |
---|
NO |
user output |
---|
NO |
Test 5
Group: 1, 2, 4, 5
Verdict: ACCEPTED
input |
---|
8 10 2 8 3 10 2 10 10 DDUUUUD |
correct output |
---|
YES 1 1 3 1 1 1 7 |
user output |
---|
YES 1 1 3 1 1 1 1000000 |
Test 6
Group: 2, 4, 5
Verdict: WRONG ANSWER
input |
---|
15 73 74 97 82 19 50 26 51 56 93 ... |
correct output |
---|
YES 1 2 3 1 1 3 1 1 1 10 1 3 1 1 |
user output |
---|
YES 1 2 1 4 1 6 1 1 1 1000000 1 3 ... |
Test 7
Group: 2, 4, 5
Verdict: ACCEPTED
input |
---|
15 95 71 97 77 98 76 100 62 96 69... |
correct output |
---|
YES 1 1 3 1 1 1 1 1 9 1 11 1 13 1 |
user output |
---|
YES 1 1 3 1 1 1 1 1 9 1 11 1 13 1 |
Test 8
Group: 2, 4, 5
Verdict: ACCEPTED
input |
---|
15 79 81 84 86 88 90 92 92 91 89 ... |
correct output |
---|
YES 1 2 3 4 5 6 14 1 6 5 4 3 2 1 |
user output |
---|
YES 1 2 3 4 5 6 1000000 1 6 5 4 3 ... |
Test 9
Group: 2, 4, 5
Verdict: WRONG ANSWER
input |
---|
15 97 90 87 83 79 76 74 23 24 76 ... |
correct output |
---|
YES 13 11 9 7 5 3 1 1 3 5 7 9 11 1... |
user output |
---|
YES 1 2 3 4 5 6 7 1 9 10 11 12 13 ... |
Test 10
Group: 2, 4, 5
Verdict: ACCEPTED
input |
---|
15 100 2 99 1 78 4 93 2 100 1 15 ... |
correct output |
---|
NO |
user output |
---|
NO |
Test 11
Group: 4, 5
Verdict: WRONG ANSWER
input |
---|
1000 999997 999995 999993 999991 99... |
correct output |
---|
YES 997 995 993 991 989 987 985 98... |
user output |
---|
YES 1 2 3 4 5 6 7 8 9 10 11 12 13 ... Truncated |
Test 12
Group: 5
Verdict: TIME LIMIT EXCEEDED
input |
---|
100000 999999998 999999996 999999994 ... |
correct output |
---|
YES 99997 99995 99993 99991 99989 ... |
user output |
---|
(empty) |
Test 13
Group: 3, 4, 5
Verdict: ACCEPTED
input |
---|
1000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
correct output |
---|
YES 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
user output |
---|
YES 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... Truncated |
Test 14
Group: 3, 4, 5
Verdict: ACCEPTED
input |
---|
1000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
correct output |
---|
NO |
user output |
---|
NO |
Test 15
Group: 1, 2, 4, 5
Verdict: ACCEPTED
input |
---|
5 6 7 7 6 6 UDUU |
correct output |
---|
YES 1 4 1 1 |
user output |
---|
YES 1 1000000 1 1 |
Test 16
Group: 4, 5
Verdict: WRONG ANSWER
input |
---|
30 15 12 9 88 10 26 78 23 67 14 9... |
correct output |
---|
YES 1 1 1 4 1 3 1 1 7 1 19 1 1 3 1... |
user output |
---|
YES 1 1 1 4 1 1 7 1 1 1 11 1 1 14 ... |
Test 17
Group: 4, 5
Verdict: WRONG ANSWER
input |
---|
1000 1000000 1 146324 146324 289287... |
correct output |
---|
YES 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
user output |
---|
YES 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... Truncated |
Test 18
Group: 5
Verdict: TIME LIMIT EXCEEDED
input |
---|
100000 1000000000 1 421262579 4212625... |
correct output |
---|
YES 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
user output |
---|
(empty) |
Test 19
Group: 1, 2, 4, 5
Verdict: ACCEPTED
input |
---|
8 1 3 1 2 5 1 1 2 DUUUDUU |
correct output |
---|
NO |
user output |
---|
NO |
Test 20
Group: 2, 4, 5
Verdict: WRONG ANSWER
input |
---|
15 3 1 33 13 1 11 32 8 1 19 15 25... |
correct output |
---|
YES 1 1 5 1 1 3 5 1 1 1 1 5 2 1 |
user output |
---|
YES 1 1 3 4 1 6 1 8 1 1 1 12 10000... |
Test 21
Group: 2, 4, 5
Verdict: ACCEPTED
input |
---|
15 10 2 39 41 42 34 31 28 26 24 2... |
correct output |
---|
YES 1 1 1 1 10 9 8 7 6 1 4 1 1 1 |
user output |
---|
YES 1 1 1 1 1000000 9 8 7 6 1 4 1 ... |
Test 22
Group: 2, 4, 5
Verdict: WRONG ANSWER
input |
---|
15 27 4 6 23 26 37 40 38 44 27 3 ... |
correct output |
---|
YES 1 1 1 1 5 1 7 1 3 1 1 3 1 1 |
user output |
---|
YES 1 1 1 1 5 1 7 1 1 10 1 12 1 1 |
Test 23
Group: 4, 5
Verdict: WRONG ANSWER
input |
---|
1000 3246 3562 197273 197429 197755... |
correct output |
---|
YES 1 1 1 4 5 10 3 1 1 3 7 12 1 1 ... |
user output |
---|
YES 1 1 1 4 5 6 7 8 1 10 1 12 1 1 ... Truncated |
Test 24
Group: 4, 5
Verdict: WRONG ANSWER
input |
---|
1000 503981 503487 503350 502673 50... |
correct output |
---|
YES 999 1 997 1 1 994 989 1 1 1 1 ... |
user output |
---|
YES 1000000 1 997 1 1 994 1 1 1 1 ... Truncated |
Test 25
Group: 4, 5
Verdict: ACCEPTED
input |
---|
1000 1445 1363 1749 1084 262408 263... |
correct output |
---|
NO |
user output |
---|
NO |
Test 26
Group: 5
Verdict: ACCEPTED
input |
---|
100000 209655 9167 9389 191291 198294... |
correct output |
---|
NO |
user output |
---|
NO |
Test 27
Group: 5
Verdict: WRONG ANSWER
input |
---|
100000 16295 14904 5103 13337 26939 3... |
correct output |
---|
YES 1 1 1 1 5 6 1 1 1 10 11 1 13 1... |
user output |
---|
YES 1 1 1 1 5 6 1 1 1 10 11 1 13 1... Truncated |
Test 28
Group: 5
Verdict: WRONG ANSWER
input |
---|
100000 1859 174288 15040 4631 4993844... |
correct output |
---|
YES 1 3 1 1 99997 99992 1 1 5 1 1 ... |
user output |
---|
YES 1 1 3 1 1000000 1 1 99992 9999... Truncated |
Test 29
Group: 5
Verdict: WRONG ANSWER
input |
---|
100000 959817 958289 966165 922369 92... |
correct output |
---|
YES 1 1 1 1 1 1 1 1 1 1 11 14 1 1 ... |
user output |
---|
YES 1 1 1 1 1 1 1 1 1 1 11 12 13 1... Truncated |
Test 30
Group: 1, 2, 4, 5
Verdict: ACCEPTED
input |
---|
8 2 3 2 3 5 6 7 8 UDDDUDU |
correct output |
---|
YES 1 2 1 1 5 6 7 |
user output |
---|
YES 1 2 1 1 5 6 7 |