Task: | Thieves and Prisons |
Sender: | eriksuenderhauf |
Submission time: | 2019-03-07 20:48:11 +0200 |
Language: | C++ |
Status: | READY |
Result: | 21 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 8 |
#2 | ACCEPTED | 13 |
#3 | WRONG ANSWER | 0 |
#4 | WRONG ANSWER | 0 |
#5 | WRONG ANSWER | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.04 s | 2, 4, 5 | details |
#2 | ACCEPTED | 0.05 s | 2, 4, 5 | details |
#3 | ACCEPTED | 0.04 s | 2, 4, 5 | details |
#4 | ACCEPTED | 0.05 s | 2, 4, 5 | details |
#5 | ACCEPTED | 0.04 s | 2, 4, 5 | details |
#6 | ACCEPTED | 0.04 s | 4, 5 | details |
#7 | ACCEPTED | 0.05 s | 4, 5 | details |
#8 | ACCEPTED | 0.03 s | 4, 5 | details |
#9 | ACCEPTED | 0.05 s | 1, 3, 4, 5 | details |
#10 | ACCEPTED | 0.04 s | 1, 3, 4, 5 | details |
#11 | ACCEPTED | 0.05 s | 1, 3, 4, 5 | details |
#12 | ACCEPTED | 0.04 s | 1, 3, 4, 5 | details |
#13 | ACCEPTED | 0.04 s | 1, 3, 4, 5 | details |
#14 | ACCEPTED | 0.04 s | 1, 3, 4, 5 | details |
#15 | ACCEPTED | 0.04 s | 1, 3, 4, 5 | details |
#16 | ACCEPTED | 0.05 s | 1, 3, 4, 5 | details |
#17 | ACCEPTED | 0.04 s | 1, 2, 3, 4, 5 | details |
#18 | ACCEPTED | 0.04 s | 1, 3, 4, 5 | details |
#19 | ACCEPTED | 0.17 s | 2, 5 | details |
#20 | ACCEPTED | 0.16 s | 2, 5 | details |
#21 | ACCEPTED | 0.16 s | 2, 5 | details |
#22 | ACCEPTED | 0.14 s | 5 | details |
#23 | ACCEPTED | 0.13 s | 5 | details |
#24 | WRONG ANSWER | 0.04 s | 3, 4, 5 | details |
#25 | WRONG ANSWER | 0.03 s | 3, 4, 5 | details |
#26 | WRONG ANSWER | 0.04 s | 3, 4, 5 | details |
#27 | WRONG ANSWER | 0.04 s | 3, 4, 5 | details |
#28 | ACCEPTED | 0.04 s | 4, 5 | details |
#29 | ACCEPTED | 0.04 s | 4, 5 | details |
#30 | ACCEPTED | 0.04 s | 4, 5 | details |
#31 | ACCEPTED | 0.05 s | 4, 5 | details |
#32 | ACCEPTED | 0.05 s | 2, 4, 5 | details |
#33 | ACCEPTED | 0.04 s | 2, 4, 5 | details |
#34 | ACCEPTED | 0.04 s | 2, 4, 5 | details |
#35 | ACCEPTED | 0.04 s | 2, 4, 5 | details |
#36 | WRONG ANSWER | 0.16 s | 3, 5 | details |
#37 | WRONG ANSWER | 0.16 s | 3, 5 | details |
#38 | WRONG ANSWER | 0.18 s | 3, 5 | details |
#39 | WRONG ANSWER | 0.19 s | 3, 5 | details |
#40 | ACCEPTED | 0.18 s | 5 | details |
#41 | ACCEPTED | 0.19 s | 5 | details |
#42 | ACCEPTED | 0.20 s | 5 | details |
#43 | ACCEPTED | 0.21 s | 5 | details |
#44 | ACCEPTED | 0.20 s | 2, 5 | details |
#45 | ACCEPTED | 0.20 s | 2, 5 | details |
#46 | ACCEPTED | 0.21 s | 2, 5 | details |
#47 | ACCEPTED | 0.23 s | 2, 5 | details |
Compiler report
input/code.cpp: In function 'int main()': input/code.cpp:126:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] for (int i = 0; i < arr.size(); i++) { ~~^~~~~~~~~~~~ input/code.cpp:72:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result] scanf("%d %d %d", &n, &k, &m); ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~ input/code.cpp:77:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result] scanf(" %c %d", &c, &x); ~~~~~^~~~~~~~~~~~~~~~~~
Code
//#pragma GCC optimize("O3") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define enl printf("\n") #define case(t) printf("Case #%d: ", (t)) #define ni(n) scanf("%d", &(n)) #define nl(n) scanf("%lld", &(n)) #define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i]) #define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i]) #define pri(n) printf("%d\n", (n)) #define prl(n) printf("%lld\n", (n)) #define pii pair<int, int> #define pil pair<int, long long> #define pll pair<long long, long long> #define vii vector<pii> #define vil vector<pil> #define vll vector<pll> #define vi vector<int> #define vl vector<long long> #define pb push_back #define mp make_pair #define fi first #define se second using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef cc_hash_table<int,int,hash<int>> ht; typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset; const double pi = acos(-1); const int MOD = 1e9 + 7; const int INF = 1e9 + 7; const int MAXN = 1e6 + 5; const double eps = 1e-9; int type[MAXN], con[MAXN], out[MAXN]; pii seg[MAXN]; vii ans[MAXN]; void build(int l, int r, int k) { if (l == r) { seg[k] = {INF, l}; return; } int m = (l + r) / 2; build(l, m, k * 2); build(m + 1, r, k * 2 + 1); seg[k] = min(seg[k*2],seg[k*2+1]); } pii qry(int l, int r, int k, int a, int b) { if (b < l || r < a) return {INF, 0}; if (a <= l && r <= b) return seg[k]; int m = (l + r) / 2; return min(qry(l,m,k*2,a,b),qry(m+1,r,k*2+1,a,b)); } void upd(int l, int r, int k, int a, int v) { if (a < l || r < a) return; if (a <= l && r <= a) { seg[k] = {v, l}; return; } int m = (l + r) / 2; upd(l,m,k*2,a,v); upd(m+1,r,k*2+1,a,v); seg[k] = min(seg[k*2],seg[k*2+1]); } int main() { int n, k, m; scanf("%d %d %d", &n, &k, &m); build(1, m, 1); set<int> act; for (int i = 1; i <= m; i++) { char c; int x; scanf(" %c %d", &c, &x); if (act.find(x) != act.end()) { pii val = qry(1, m, 1, con[x], i); if (val.fi == INF) return !printf("IMPOSSIBLE\n"); ans[val.se].pb({x, con[x]}); upd(1, m, 1, val.se, 1); act.erase(act.find(x)); } if (c == 'C') { con[x] = i; act.insert(x); type[i] = 1; } else { upd(1, m, 1, i, 0); type[i] = 2; } } vi tmp; int mx = INF; while (!act.empty()) { int x = *act.begin(); act.erase(act.begin()); pii val = qry(1, m, 1, con[x], m); if (val.fi == INF) { mx = min(mx, con[x]); tmp.pb(con[x]); continue; } ans[val.se].pb({x, con[x]}); upd(1, m, 1, val.se, 1); } for (int i = 1; i <= m; i++) if (type[i] == 2 && ans[i].empty()) return !printf("IMPOSSIBLE\n"); act.clear(); for (int i = 1; i <= k; i++) act.insert(i); vii arr; for (int i = 1; i <= m; i++) { if (type[i] != 2) continue; int mi = INF; for (pii nx: ans[i]) { mi = min(nx.se, mi); } arr.pb({mi, i}); arr.pb({i, i}); } if (mx != INF) arr.pb({mx, m + 1}); sort(arr.begin(), arr.end()); for (int i = 0; i < arr.size(); i++) { int lo = arr[i].fi, hi = arr[i].se; if (lo == hi) { act.insert(out[lo]); } else { if (act.empty()) return !printf("IMPOSSIBLE\n"); int val = *act.begin(); act.erase(act.begin()); out[hi] = val; } } for (int i = 1; i <= m; i++) { if (type[i] != 2) continue; for (pii nx: ans[i]) out[nx.se] = out[i]; } for (int i: tmp) out[i] = out[m + 1]; for (int i = 1; i <= m; i++) printf("%d ", out[i]); enl; return 0; }
Test details
Test 1
Group: 2, 4, 5
Verdict: ACCEPTED
input |
---|
1 1 1 C 1 |
correct output |
---|
1 |
user output |
---|
1 |
Test 2
Group: 2, 4, 5
Verdict: ACCEPTED
input |
---|
1 1 1 O 1 |
correct output |
---|
IMPOSSIBLE |
user output |
---|
IMPOSSIBLE |
Test 3
Group: 2, 4, 5
Verdict: ACCEPTED
input |
---|
1 1 2 C 1 C 1 |
correct output |
---|
IMPOSSIBLE |
user output |
---|
IMPOSSIBLE |
Test 4
Group: 2, 4, 5
Verdict: ACCEPTED
input |
---|
1 1 2 C 1 O 1 |
correct output |
---|
IMPOSSIBLE |
user output |
---|
IMPOSSIBLE |
Test 5
Group: 2, 4, 5
Verdict: ACCEPTED
input |
---|
1 1 2 O 1 C 1 |
correct output |
---|
IMPOSSIBLE |
user output |
---|
IMPOSSIBLE |
Test 6
Group: 4, 5
Verdict: ACCEPTED
input |
---|
2 1 2 C 1 C 2 |
correct output |
---|
1 1 |
user output |
---|
1 1 |
Test 7
Group: 4, 5
Verdict: ACCEPTED
input |
---|
2 1 2 C 1 O 1 |
correct output |
---|
IMPOSSIBLE |
user output |
---|
IMPOSSIBLE |
Test 8
Group: 4, 5
Verdict: ACCEPTED
input |
---|
2 1 2 C 1 O 2 |
correct output |
---|
1 1 |
user output |
---|
1 1 |
Test 9
Group: 1, 3, 4, 5
Verdict: ACCEPTED
input |
---|
3 2 5 C 1 C 2 O 3 C 1 ... |
correct output |
---|
1 1 1 1 1 |
user output |
---|
1 1 1 1 1 |
Test 10
Group: 1, 3, 4, 5
Verdict: ACCEPTED
input |
---|
3 2 5 C 1 C 2 O 3 O 3 ... |
correct output |
---|
2 1 2 1 1 |
user output |
---|
1 2 1 2 1 |
Test 11
Group: 1, 3, 4, 5
Verdict: ACCEPTED
input |
---|
3 2 5 C 1 C 2 O 3 O 1 ... |
correct output |
---|
2 1 2 1 1 |
user output |
---|
1 2 1 2 1 |
Test 12
Group: 1, 3, 4, 5
Verdict: ACCEPTED
input |
---|
3 2 5 C 1 C 2 O 1 O 3 ... |
correct output |
---|
IMPOSSIBLE |
user output |
---|
IMPOSSIBLE |
Test 13
Group: 1, 3, 4, 5
Verdict: ACCEPTED
input |
---|
3 2 4 C 1 O 2 C 1 O 3 |
correct output |
---|
1 1 1 1 |
user output |
---|
1 1 1 1 |
Test 14
Group: 1, 3, 4, 5
Verdict: ACCEPTED
input |
---|
3 2 4 C 1 O 2 C 2 O 1 |
correct output |
---|
1 1 1 1 |
user output |
---|
1 1 1 1 |
Test 15
Group: 1, 3, 4, 5
Verdict: ACCEPTED
input |
---|
3 2 3 C 1 C 2 C 3 |
correct output |
---|
1 1 1 |
user output |
---|
1 1 1 |
Test 16
Group: 1, 3, 4, 5
Verdict: ACCEPTED
input |
---|
3 2 3 O 1 C 2 C 3 |
correct output |
---|
IMPOSSIBLE |
user output |
---|
IMPOSSIBLE |
Test 17
Group: 1, 2, 3, 4, 5
Verdict: ACCEPTED
input |
---|
2 2 7 C 1 O 2 O 2 O 2 ... |
correct output |
---|
IMPOSSIBLE |
user output |
---|
IMPOSSIBLE |
Test 18
Group: 1, 3, 4, 5
Verdict: ACCEPTED
input |
---|
4 2 5 C 2 O 3 C 1 O 4 ... |
correct output |
---|
1 1 1 1 1 |
user output |
---|
1 1 1 1 1 |
Test 19
Group: 2, 5
Verdict: ACCEPTED
input |
---|
100000 100000 100000 C 1 C 2 C 3 C 4 ... |
correct output |
---|
50000 49999 49998 49997 49996 ... |
user output |
---|
1 2 3 4 5 6 7 8 9 10 11 12 13 ... Truncated |
Test 20
Group: 2, 5
Verdict: ACCEPTED
input |
---|
100000 100000 100000 C 1 C 2 C 3 C 4 ... |
correct output |
---|
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
user output |
---|
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... Truncated |
Test 21
Group: 2, 5
Verdict: ACCEPTED
input |
---|
100000 100000 100000 C 1 C 2 C 3 C 4 ... |
correct output |
---|
20000 20000 20000 20000 20000 ... |
user output |
---|
1 2 3 4 5 6 7 8 9 10 11 12 13 ... Truncated |
Test 22
Group: 5
Verdict: ACCEPTED
input |
---|
100000 100 100000 C 1 C 2 C 3 C 4 ... |
correct output |
---|
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
user output |
---|
1 2 3 4 5 6 7 8 9 10 11 12 13 ... Truncated |
Test 23
Group: 5
Verdict: ACCEPTED
input |
---|
100000 99 100000 C 1 C 2 C 3 C 4 ... |
correct output |
---|
IMPOSSIBLE |
user output |
---|
IMPOSSIBLE |
Test 24
Group: 3, 4, 5
Verdict: WRONG ANSWER
input |
---|
500 2 500 C 384 O 62 C 387 O 473 ... |
correct output |
---|
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
user output |
---|
IMPOSSIBLE |
Test 25
Group: 3, 4, 5
Verdict: WRONG ANSWER
input |
---|
500 2 500 C 384 O 62 C 387 O 473 ... |
correct output |
---|
1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 ... |
user output |
---|
IMPOSSIBLE |
Test 26
Group: 3, 4, 5
Verdict: WRONG ANSWER
input |
---|
500 2 500 C 384 O 62 C 387 O 473 ... |
correct output |
---|
1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 ... |
user output |
---|
IMPOSSIBLE |
Test 27
Group: 3, 4, 5
Verdict: WRONG ANSWER
input |
---|
500 2 500 C 384 O 62 C 387 C 473 ... |
correct output |
---|
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
user output |
---|
IMPOSSIBLE |
Test 28
Group: 4, 5
Verdict: ACCEPTED
input |
---|
500 250 500 C 384 O 62 C 387 O 473 ... |
correct output |
---|
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
user output |
---|
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... Truncated |
Test 29
Group: 4, 5
Verdict: ACCEPTED
input |
---|
500 250 500 C 384 O 62 C 387 O 473 ... |
correct output |
---|
1 1 1 1 1 1 1 1 1 1 1 1 2 1 3 ... |
user output |
---|
1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 ... Truncated |
Test 30
Group: 4, 5
Verdict: ACCEPTED
input |
---|
500 250 500 C 384 O 62 C 387 O 473 ... |
correct output |
---|
1 1 1 1 1 3 2 3 3 2 2 2 5 4 2 ... |
user output |
---|
1 1 1 1 1 2 3 2 2 3 3 3 3 4 5 ... Truncated |
Test 31
Group: 4, 5
Verdict: ACCEPTED
input |
---|
500 250 500 C 384 O 62 C 387 C 473 ... |
correct output |
---|
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
user output |
---|
1 1 1 2 3 4 5 6 7 8 4 4 9 4 10... Truncated |
Test 32
Group: 2, 4, 5
Verdict: ACCEPTED
input |
---|
500 500 500 C 384 O 62 C 387 O 473 ... |
correct output |
---|
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
user output |
---|
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... Truncated |
Test 33
Group: 2, 4, 5
Verdict: ACCEPTED
input |
---|
500 500 500 C 384 O 62 C 387 O 473 ... |
correct output |
---|
1 1 1 1 1 1 1 1 1 1 1 1 2 1 3 ... |
user output |
---|
1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 ... Truncated |
Test 34
Group: 2, 4, 5
Verdict: ACCEPTED
input |
---|
500 500 500 C 384 O 62 C 387 O 473 ... |
correct output |
---|
1 1 1 1 2 1 3 3 3 2 2 2 2 4 5 ... |
user output |
---|
1 1 1 1 1 2 3 3 3 1 1 1 1 4 5 ... Truncated |
Test 35
Group: 2, 4, 5
Verdict: ACCEPTED
input |
---|
500 500 500 C 384 O 62 C 387 C 473 ... |
correct output |
---|
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
user output |
---|
1 1 1 1 1 1 2 3 1 1 1 4 5 6 1 ... Truncated |
Test 36
Group: 3, 5
Verdict: WRONG ANSWER
input |
---|
100000 2 100000 C 89384 O 54062 C 85387 O 53318 ... |
correct output |
---|
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
user output |
---|
IMPOSSIBLE |
Test 37
Group: 3, 5
Verdict: WRONG ANSWER
input |
---|
100000 2 100000 C 89384 O 54062 C 85387 O 53318 ... |
correct output |
---|
1 1 1 1 1 1 1 1 1 1 1 1 2 2 1 ... |
user output |
---|
IMPOSSIBLE |
Test 38
Group: 3, 5
Verdict: WRONG ANSWER
input |
---|
100000 2 100000 C 89384 O 54062 C 85387 O 53318 ... |
correct output |
---|
1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 ... |
user output |
---|
IMPOSSIBLE |
Test 39
Group: 3, 5
Verdict: WRONG ANSWER
input |
---|
100000 2 100000 C 89384 O 54062 C 85387 C 53318 ... |
correct output |
---|
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
user output |
---|
IMPOSSIBLE |
Test 40
Group: 5
Verdict: ACCEPTED
input |
---|
100000 50000 100000 C 89384 O 54062 C 85387 O 53318 ... |
correct output |
---|
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
user output |
---|
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... Truncated |
Test 41
Group: 5
Verdict: ACCEPTED
input |
---|
100000 50000 100000 C 89384 O 54062 C 85387 O 53318 ... |
correct output |
---|
1 1 1 1 1 1 1 1 1 1 1 1 3 2 1 ... |
user output |
---|
1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 ... Truncated |
Test 42
Group: 5
Verdict: ACCEPTED
input |
---|
100000 50000 100000 C 89384 O 54062 C 85387 O 53318 ... |
correct output |
---|
1 1 1 1 1 3 2 3 3 3 3 3 3 4 5 ... |
user output |
---|
1 1 1 1 1 2 3 2 2 2 2 2 2 4 5 ... Truncated |
Test 43
Group: 5
Verdict: ACCEPTED
input |
---|
100000 50000 100000 C 89384 O 54062 C 85387 C 53318 ... |
correct output |
---|
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
user output |
---|
1 1 1 2 1 1 3 4 1 5 6 7 8 9 10... Truncated |
Test 44
Group: 2, 5
Verdict: ACCEPTED
input |
---|
100000 100000 100000 C 89384 O 54062 C 85387 O 53318 ... |
correct output |
---|
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
user output |
---|
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... Truncated |
Test 45
Group: 2, 5
Verdict: ACCEPTED
input |
---|
100000 100000 100000 C 89384 O 54062 C 85387 O 53318 ... |
correct output |
---|
1 1 1 1 1 1 1 1 1 1 1 1 3 2 1 ... |
user output |
---|
1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 ... Truncated |
Test 46
Group: 2, 5
Verdict: ACCEPTED
input |
---|
100000 100000 100000 C 89384 O 54062 C 85387 O 53318 ... |
correct output |
---|
1 1 1 1 2 1 3 3 3 3 3 3 4 5 3 ... |
user output |
---|
1 1 1 1 1 2 3 3 3 3 3 3 3 4 5 ... Truncated |
Test 47
Group: 2, 5
Verdict: ACCEPTED
input |
---|
100000 100000 100000 C 89384 O 54062 C 85387 C 53318 ... |
correct output |
---|
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
user output |
---|
1 1 1 2 3 4 5 6 3 3 7 8 9 3 10... Truncated |