Task: | Thieves and Prisons |
Sender: | Marcel Wrzos-Kaminski |
Submission time: | 2019-03-06 15:16:29 +0200 |
Language: | C++ |
Status: | READY |
Result: | 0 |
group | verdict | score |
---|---|---|
#1 | WRONG ANSWER | 0 |
#2 | WRONG ANSWER | 0 |
#3 | WRONG ANSWER | 0 |
#4 | WRONG ANSWER | 0 |
#5 | WRONG ANSWER | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.02 s | 2, 4, 5 | details |
#2 | ACCEPTED | 0.01 s | 2, 4, 5 | details |
#3 | ACCEPTED | 0.01 s | 2, 4, 5 | details |
#4 | WRONG ANSWER | 0.02 s | 2, 4, 5 | details |
#5 | ACCEPTED | 0.02 s | 2, 4, 5 | details |
#6 | ACCEPTED | 0.02 s | 4, 5 | details |
#7 | WRONG ANSWER | 0.02 s | 4, 5 | details |
#8 | ACCEPTED | 0.02 s | 4, 5 | details |
#9 | ACCEPTED | 0.03 s | 1, 3, 4, 5 | details |
#10 | ACCEPTED | 0.01 s | 1, 3, 4, 5 | details |
#11 | ACCEPTED | 0.02 s | 1, 3, 4, 5 | details |
#12 | WRONG ANSWER | 0.02 s | 1, 3, 4, 5 | details |
#13 | ACCEPTED | 0.02 s | 1, 3, 4, 5 | details |
#14 | ACCEPTED | 0.01 s | 1, 3, 4, 5 | details |
#15 | ACCEPTED | 0.02 s | 1, 3, 4, 5 | details |
#16 | ACCEPTED | 0.02 s | 1, 3, 4, 5 | details |
#17 | ACCEPTED | 0.02 s | 1, 2, 3, 4, 5 | details |
#18 | ACCEPTED | 0.02 s | 1, 3, 4, 5 | details |
#19 | TIME LIMIT EXCEEDED | -- | 2, 5 | details |
#20 | TIME LIMIT EXCEEDED | -- | 2, 5 | details |
#21 | TIME LIMIT EXCEEDED | -- | 2, 5 | details |
#22 | ACCEPTED | 0.09 s | 5 | details |
#23 | ACCEPTED | 0.08 s | 5 | details |
#24 | WRONG ANSWER | 0.02 s | 3, 4, 5 | details |
#25 | WRONG ANSWER | 0.02 s | 3, 4, 5 | details |
#26 | ACCEPTED | 0.02 s | 3, 4, 5 | details |
#27 | ACCEPTED | 0.01 s | 3, 4, 5 | details |
#28 | ACCEPTED | 0.03 s | 4, 5 | details |
#29 | ACCEPTED | 0.02 s | 4, 5 | details |
#30 | ACCEPTED | 0.02 s | 4, 5 | details |
#31 | ACCEPTED | 0.01 s | 4, 5 | details |
#32 | ACCEPTED | 0.01 s | 2, 4, 5 | details |
#33 | ACCEPTED | 0.02 s | 2, 4, 5 | details |
#34 | ACCEPTED | 0.03 s | 2, 4, 5 | details |
#35 | ACCEPTED | 0.01 s | 2, 4, 5 | details |
#36 | WRONG ANSWER | 0.09 s | 3, 5 | details |
#37 | WRONG ANSWER | 0.08 s | 3, 5 | details |
#38 | WRONG ANSWER | 0.09 s | 3, 5 | details |
#39 | WRONG ANSWER | 0.09 s | 3, 5 | details |
#40 | ACCEPTED | 0.77 s | 5 | details |
#41 | ACCEPTED | 0.77 s | 5 | details |
#42 | ACCEPTED | 0.74 s | 5 | details |
#43 | ACCEPTED | 0.52 s | 5 | details |
#44 | ACCEPTED | 0.77 s | 2, 5 | details |
#45 | ACCEPTED | 0.77 s | 2, 5 | details |
#46 | ACCEPTED | 0.72 s | 2, 5 | details |
#47 | ACCEPTED | 0.52 s | 2, 5 | details |
Code
#include <vector> #include <iostream> #include <algorithm> using namespace std; vector<int> openings; //sorted list of openings; vector<int> val; vector<int> lC; vector<int> rC; vector<int> parent; int root; int query(int value){ int best_ind = -1; int cur_best = 100000; int cur_node; int next = root; while(next != -1){ cur_node = next; if(val[cur_node] >= value and val[cur_node] < cur_best){ cur_best = val[cur_node]; best_ind = cur_node; } if(val[cur_node] >= cur_best){ next = lC[cur_node]; }else{ next = rC[cur_node]; } } return best_ind; } int find_min(int node){ int cur_node = node; while(lC[cur_node] != -1){ cur_node = lC[cur_node]; } return cur_node; } void del(int nodeId){ int child = 0; if(lC[nodeId] != -1){ child += 1; } if(rC[nodeId] != -1){ child += 1; } int p; int c; if(child == 0){ p = parent[nodeId]; if(p == -1){ root = -1; }else if(lC[p] == nodeId){ lC[p] = -1; }else{ rC[p] = -1; } }else if(child == 1){ if(lC[nodeId] != -1){ c = lC[nodeId]; }else{ c = rC[nodeId]; } p = parent[nodeId]; if(p == -1){ root = c; }else{ if(lC[p] == nodeId){ lC[p] = c; }else{ rC[p] = c; } } parent[c] = p; }else{ int rep = find_min(rC[nodeId]); val[nodeId] = val[rep]; del(rep); } } int gen(int start, int end){ if (start > end){ return -1; } int mid = (start+end)/2; int nodeVal = openings[mid]; int nodeId = val.size(); int temp; val.push_back(nodeVal); lC.push_back(-1); rC.push_back(-1); parent.push_back(-1); temp = gen(start, mid-1); lC[nodeId] = temp; temp = gen(mid+1, end); rC[nodeId] = temp; if(lC[nodeId] != -1){ parent[lC[nodeId]] = nodeId; } if(rC[nodeId] != -1){ parent[rC[nodeId]] = nodeId; } return nodeId; } int main(){ int n, k, m; char e; int c; int o = 0; bool possible = true; cin >> n >> k >> m; vector<int> catches(0); //sorted list of catches vector<bool> eventType(0); //true - catch, false openings vector<int> eventCarrier(0); //who did that vector<int> eventPrison(0); //where it happened vector<int> cE(n, -1); //thiev -> eventId when caught if unclaimed, else -1; for(int i = 0; i < m; i++){ // i is current event cin >> e >> c; if(e == 'C'){ eventType.push_back(true); eventCarrier.push_back(c-1); eventPrison.push_back(-1); }else{ eventType.push_back(false); eventCarrier.push_back(c-1); eventPrison.push_back(o); o = (o+1)%k; openings.push_back(i); } } root = gen(0, openings.size() - 1); bool type; int carrier; int bN; for(int i = 0; i < m; i++){ type = eventType[i]; carrier = eventCarrier[i]; if(cE[carrier] != -1){ //gotta get my homie out bN = query(cE[carrier]); //validate opening auto minO = lower_bound(openings.begin(), openings.end(), cE[carrier]); auto maxO = minO; for(int i = 0; i < k-1; i++){ maxO++; if(maxO == openings.end()){ maxO--; break; } } if(bN == -1 or val[bN] > *maxO){ //ugyldig if(minO == openings.end() or *minO > i){ //homie rekker ikke å komme ut D: possible = false; break; }else{ eventPrison[cE[carrier]] = eventPrison[*minO]; cE[carrier] = -1; } }else{ //gyldig eventPrison[cE[carrier]] = eventPrison[val[bN]]; cE[carrier] = -1; del(bN); } } if(type == true){ cE[carrier] = i; } } for(int i = 0; i < n; i++){ if(cE[i] != -1){ bN = query(cE[i]); auto minO = lower_bound(openings.begin(), openings.end(), cE[i]); auto maxO = minO; for(int i = 0; i < k-1; i++){ maxO++; if(maxO == openings.end()){ maxO--; break; } } if(bN == -1 or val[bN] > *maxO){ eventPrison[cE[i]] = 0; cE[i] = -1; }else{ eventPrison[cE[i]] = eventPrison[val[bN]]; cE[i] = -1; del(bN); } } } if(root != -1){ possible = false; } if(not possible){ cout << "IMPOSSIBLE" << endl; }else{ for(int i = 0; i < m; i++){ cout << eventPrison[i] + 1 << " "; } cout << endl; } 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: WRONG ANSWER
input |
---|
1 1 2 C 1 O 1 |
correct output |
---|
IMPOSSIBLE |
user output |
---|
1 1 |
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: WRONG ANSWER
input |
---|
2 1 2 C 1 O 1 |
correct output |
---|
IMPOSSIBLE |
user output |
---|
1 1 |
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: WRONG ANSWER
input |
---|
3 2 5 C 1 C 2 O 1 O 3 ... |
correct output |
---|
IMPOSSIBLE |
user output |
---|
1 2 1 2 1 |
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 2 2 |
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 2 2 |
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 2 2 1 |
Test 19
Group: 2, 5
Verdict: TIME LIMIT EXCEEDED
input |
---|
100000 100000 100000 C 1 C 2 C 3 C 4 ... |
correct output |
---|
50000 49999 49998 49997 49996 ... |
user output |
---|
(empty) |
Test 20
Group: 2, 5
Verdict: TIME LIMIT EXCEEDED
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 |
---|
(empty) |
Test 21
Group: 2, 5
Verdict: TIME LIMIT EXCEEDED
input |
---|
100000 100000 100000 C 1 C 2 C 3 C 4 ... |
correct output |
---|
20000 20000 20000 20000 20000 ... |
user output |
---|
(empty) |
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: ACCEPTED
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 |
---|
1 1 2 2 1 2 1 1 1 2 1 1 1 1 2 ... Truncated |
Test 27
Group: 3, 4, 5
Verdict: ACCEPTED
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 |
---|
1 1 2 2 2 2 1 1 2 2 2 1 2 1 1 ... Truncated |
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 2 2 3 3 4 4 5 5 6 6 7 7 8 ... 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 2 2 3 3 4 4 5 5 6 6 9 8 7 ... 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 2 2 7 3 4 3 10 4 5 5 6 8 9... 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 8 23 3 2 64 7 17 4 1 1 40 ... 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 2 2 3 3 4 4 5 5 6 6 7 7 8 ... 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 2 2 3 3 4 4 5 5 6 6 8 9 7 ... 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 2 2 4 8 3 3 9 4 5 5 10 7 6... 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 2 4 41 1 1 1 3 7 28 ... 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 2 2 3 3 4 4 5 5 6 6 7 7 8 ... 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 2 2 3 3 4 4 5 5 6 6 7 9 8 ... 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 2 2 9 3 8 3 4 4 5 5 10 7 6... 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 2 8 1 1 1887 1297 1 4 6419... 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 2 2 3 3 4 4 5 5 6 6 7 7 8 ... 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 2 2 3 3 4 4 5 5 6 6 7 8 9 ... 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 2 2 8 9 3 3 4 4 5 5 7 6 10... 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 2339 3482 1 3 8402 5 2 1 1... Truncated |