Task: | Thin Ice |
Sender: | John Hedin |
Submission time: | 2024-03-06 19:56:36 +0200 |
Language: | C++ (C++17) |
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 |
#6 | WRONG ANSWER | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.00 s | 1, 5, 6 | details |
#2 | WRONG ANSWER | 0.00 s | 1, 5, 6 | details |
#3 | ACCEPTED | 0.00 s | 1, 5, 6 | details |
#4 | RUNTIME ERROR | 0.00 s | 1, 5, 6 | details |
#5 | WRONG ANSWER | 0.00 s | 1, 5, 6 | details |
#6 | RUNTIME ERROR | 0.00 s | 1, 5, 6 | details |
#7 | WRONG ANSWER | 0.00 s | 1, 5, 6 | details |
#8 | WRONG ANSWER | 0.00 s | 1, 5, 6 | details |
#9 | WRONG ANSWER | 0.00 s | 1, 2, 5, 6 | details |
#10 | RUNTIME ERROR | 0.03 s | 2, 6 | details |
#11 | RUNTIME ERROR | 0.03 s | 2, 6 | details |
#12 | RUNTIME ERROR | 0.03 s | 2, 6 | details |
#13 | RUNTIME ERROR | 0.04 s | 2, 6 | details |
#14 | RUNTIME ERROR | 0.03 s | 2, 6 | details |
#15 | RUNTIME ERROR | 0.04 s | 2, 6 | details |
#16 | RUNTIME ERROR | 0.03 s | 2, 6 | details |
#17 | RUNTIME ERROR | 0.03 s | 2, 6 | details |
#18 | RUNTIME ERROR | 0.03 s | 2, 6 | details |
#19 | RUNTIME ERROR | 0.03 s | 2, 6 | details |
#20 | RUNTIME ERROR | 0.03 s | 2, 6 | details |
#21 | ACCEPTED | 0.05 s | 2, 6 | details |
#22 | WRONG ANSWER | 0.00 s | 3, 4, 5, 6 | details |
#23 | WRONG ANSWER | 0.00 s | 3, 4, 5, 6 | details |
#24 | WRONG ANSWER | 0.00 s | 3, 4, 5, 6 | details |
#25 | WRONG ANSWER | 0.00 s | 3, 4, 5, 6 | details |
#26 | WRONG ANSWER | 0.00 s | 3, 4, 5, 6 | details |
#27 | WRONG ANSWER | 0.00 s | 3, 4, 5, 6 | details |
#28 | RUNTIME ERROR | 0.01 s | 4, 6 | details |
#29 | RUNTIME ERROR | 0.01 s | 4, 6 | details |
#30 | RUNTIME ERROR | 0.01 s | 4, 6 | details |
#31 | RUNTIME ERROR | 0.01 s | 4, 6 | details |
#32 | RUNTIME ERROR | 0.01 s | 4, 6 | details |
#33 | RUNTIME ERROR | 0.01 s | 4, 6 | details |
#34 | RUNTIME ERROR | 0.01 s | 4, 6 | details |
#35 | RUNTIME ERROR | 0.00 s | 5, 6 | details |
#36 | RUNTIME ERROR | 0.00 s | 5, 6 | details |
#37 | RUNTIME ERROR | 0.00 s | 5, 6 | details |
#38 | RUNTIME ERROR | 0.00 s | 5, 6 | details |
#39 | RUNTIME ERROR | 0.00 s | 5, 6 | details |
#40 | RUNTIME ERROR | 0.00 s | 5, 6 | details |
#41 | RUNTIME ERROR | 0.00 s | 5, 6 | details |
#42 | TIME LIMIT EXCEEDED | -- | 6 | details |
#43 | RUNTIME ERROR | 0.07 s | 6 | details |
#44 | ACCEPTED | 0.65 s | 6 | details |
#45 | RUNTIME ERROR | 0.06 s | 6 | details |
#46 | RUNTIME ERROR | 0.07 s | 6 | details |
#47 | RUNTIME ERROR | 0.07 s | 6 | details |
#48 | RUNTIME ERROR | 0.07 s | 6 | details |
Code
#include <iostream> #include <vector> #include <set> using namespace std; typedef long long ll; typedef pair<ll,ll> pll; typedef vector<ll> vll; typedef vector<vll> vvll; typedef set<pll> sp; const bool debug = false; #define rep(a,b,c) for(ll a = b; a < c; a++) #define rrep(a,b,c) for(ll a = c-1; a >= b; a--) #define itr_rep(a,b,_type) for(_type::iterator a = b.begin(); a != b.end(); a++) #define pb push_back #define mp make_pair #define sz size #define all(a) a.begin(),a.end() bool try_D(ll D); ll uf_parent(ll a); ll uf_merge(ll a, ll b); ll n; ll m; vll d; ll coords(ll i, ll j) {return (m+2)*(i+1) + (j+1);} vll uf_par; vll uf_size; int main() { cin >> n; cin >> m; d.resize(n*m,0); rep(i,0,n) { rep(j,0,m) { cin >> d[coords(i,j)]; } } ll lo = 1; // possible ll hi = n*m + 1; // impossible ll mid = (lo+hi)/2; while (hi - lo > 1) { mid = (lo+hi)/2; bool possible = try_D(mid); if (debug) {cout << possible << " " << mid << endl;} if (possible) {lo = mid;} else {hi = mid;} } cout << lo << endl; return 0; } bool try_D(ll D) { // id = n*i + j i = id/n j = id%n sp q; // < -d[i][j], id> // We want to acess the one with the largest d[i][j] by calling begin() uf_par.clear(); uf_size.clear(); uf_par.resize((n+2)*(m+2),0); rep(i,0,(n+2)*(m+2)) {uf_par[i]=i;} uf_size.resize((n+2)*(m+2),1); // uf_size == 0 means that we are off the board rep(i,coords(-1,-1),coords(-1,m)+1) {uf_size[i] = 0;} rep(i,coords(n,-1),coords(n,m)+1) {uf_size[i] = 0;} for(ll i = coords(-1,-1); i < coords(n,-1)+1; i+= (m+2)) {uf_size[i] = 0;} for(ll i = coords(-1,m); i < coords(n,m)+1; i+= (m+2)) {uf_size[i] = 0;} vector<bool> is_cmp; is_cmp.resize((n+2)*(m+2),false); // loop over all edge squares and add any with d >= D rep(id,coords(0,0),coords(0,m-1)+1) {if (d[id] >= D) { q.insert(mp(-d[id],id)); is_cmp[id] = true; }} rep(id,coords(n-1,0),coords(n-1,m-1)+1) {if (d[id] >= D) { q.insert(mp(-d[id],id)); is_cmp[id] = true; }} for(ll id = coords(0,0); id < coords(n-1,0)+1; id += (m+2)) {if (d[id] >= D) { q.insert(mp(-d[id],id)); is_cmp[id] = true; }} for(ll id = coords(0,m-1); id < coords(n-1,m-1)+1; id += (m+2)) {if (d[id] >= D) { q.insert(mp(-d[id],id)); is_cmp[id] = true; }} while (q.size() > 0) { ll curr = (*q.begin()).second; q.erase(q.begin()); if (debug) {cout << "curr: " << (curr/(m+2))-1 << "," << (curr%(m+2))-1 << endl;} ll other[4] = {curr+1,curr-1,curr+(m+2),curr-(m+2)}; ll sizes[4]; rep(i,0,4) {sizes[i] = uf_size[uf_parent(other[i])];} rep(i,0,4) { if (is_cmp[other[i]]) { // other is component if (d[curr] >= D - sizes[i]) { // can be added to this component uf_merge(curr,other[i]); is_cmp[curr] = true; } } } if (is_cmp[curr]) { // If we are now a component rep(i,0,4) { if (is_cmp[other[i]]) { // other is component uf_merge(curr,other[i]); // components can always be merged } else if (sizes[i] != 0) { // other isn't out of bound q.insert(mp(-d[other[i]],other[i])); // merge means new borders } } } if (uf_size[uf_parent(curr)] >= D) { if (debug) { cout << ":" << curr << " " << uf_parent(curr) << " " << uf_size[uf_parent(curr)] << endl; rep(i,0,n) {rep(j,0,m) {cout << uf_par[coords(i,j)] << " ";} cout << endl;} cout << endl; rep(i,0,n) {rep(j,0,m) {cout << uf_size[uf_par[coords(i,j)]] << " ";} cout << endl;} } return true; } } return false; } ll uf_parent(ll a) { while (uf_par[a] != uf_par[uf_par[a]]) {uf_par[a] = uf_par[uf_par[a]];} return uf_par[a]; } ll uf_merge(ll a, ll b) { ll ap = uf_parent(a); ll bp = uf_parent(b); if (ap == bp) {return ap;} if (uf_size[bp] > uf_size[ap]) {swap(ap,bp);} uf_par[bp] = ap; uf_size[ap] += uf_size[bp]; return ap; }
Test details
Test 1
Group: 1, 5, 6
Verdict: ACCEPTED
input |
---|
4 4 9 11 5 7 7 9 14 3 1 3 2 3 11 4 14 8 |
correct output |
---|
10 |
user output |
---|
10 |
Test 2
Group: 1, 5, 6
Verdict: WRONG ANSWER
input |
---|
5 3 10 7 11 8 5 5 12 9 10 3 13 9 ... |
correct output |
---|
10 |
user output |
---|
8 |
Test 3
Group: 1, 5, 6
Verdict: ACCEPTED
input |
---|
4 4 3 2 2 2 5 1 1 1 8 4 1 1 7 6 2 1 |
correct output |
---|
8 |
user output |
---|
8 |
Test 4
Group: 1, 5, 6
Verdict: RUNTIME ERROR
input |
---|
3 5 1 11 1 3 5 4 12 7 8 7 13 14 14 9 4 |
correct output |
---|
14 |
user output |
---|
(empty) |
Error:
code: malloc.c:2617: sysmalloc: Assertion `(old_top == initial_top (av) && old_size == 0)...
Test 5
Group: 1, 5, 6
Verdict: WRONG ANSWER
input |
---|
5 3 11 8 12 11 11 12 6 2 3 11 8 13 ... |
correct output |
---|
12 |
user output |
---|
8 |
Test 6
Group: 1, 5, 6
Verdict: RUNTIME ERROR
input |
---|
3 5 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 |
correct output |
---|
14 |
user output |
---|
(empty) |
Error:
code: malloc.c:2617: sysmalloc: Assertion `(old_top == initial_top (av) && old_size == 0)...
Test 7
Group: 1, 5, 6
Verdict: WRONG ANSWER
input |
---|
4 4 12 8 6 5 12 9 6 1 10 1 3 2 8 1 1 1 |
correct output |
---|
12 |
user output |
---|
10 |
Test 8
Group: 1, 5, 6
Verdict: WRONG ANSWER
input |
---|
4 4 8 3 15 14 10 12 2 4 5 16 9 6 7 13 1 11 |
correct output |
---|
13 |
user output |
---|
8 |
Test 9
Group: 1, 2, 5, 6
Verdict: WRONG ANSWER
input |
---|
4 4 4 1 1 2 3 5 4 2 2 2 1 2 1 4 3 4 |
correct output |
---|
4 |
user output |
---|
8 |
Test 10
Group: 2, 6
Verdict: RUNTIME ERROR
input |
---|
10 20000 5 3 2 1 3 2 3 3 4 5 1 1 2 3 5 ... |
correct output |
---|
5 |
user output |
---|
(empty) |
Test 11
Group: 2, 6
Verdict: RUNTIME ERROR
input |
---|
10 20000 1 2 1 2 1 2 1 2 1 1 1 1 2 1 1 ... |
correct output |
---|
3 |
user output |
---|
(empty) |
Test 12
Group: 2, 6
Verdict: RUNTIME ERROR
input |
---|
10 20000 3 2 2 3 1 2 1 4 4 3 1 4 3 2 4 ... |
correct output |
---|
5 |
user output |
---|
(empty) |
Test 13
Group: 2, 6
Verdict: RUNTIME ERROR
input |
---|
20000 10 1 1 3 1 2 1 1 1 1 1 1 2 2 1 1 1 1 2 1 1 2 1 1 1 2 2 1 1 1 2 1 1 1 1 1 1 1 1 1 1 ... |
correct output |
---|
4 |
user output |
---|
(empty) |
Test 14
Group: 2, 6
Verdict: RUNTIME ERROR
input |
---|
10 20000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
correct output |
---|
3 |
user output |
---|
(empty) |
Test 15
Group: 2, 6
Verdict: RUNTIME ERROR
input |
---|
10 20000 3 1 3 1 2 1 2 3 2 2 1 2 1 1 2 ... |
correct output |
---|
3 |
user output |
---|
(empty) |
Test 16
Group: 2, 6
Verdict: RUNTIME ERROR
input |
---|
10 20000 1 2 2 2 1 2 3 1 2 2 2 1 2 2 2 ... |
correct output |
---|
4 |
user output |
---|
(empty) |
Test 17
Group: 2, 6
Verdict: RUNTIME ERROR
input |
---|
10 20000 3 3 2 3 2 3 2 2 2 2 2 1 3 2 1 ... |
correct output |
---|
4 |
user output |
---|
(empty) |
Test 18
Group: 2, 6
Verdict: RUNTIME ERROR
input |
---|
10 20000 1 3 3 1 1 4 3 3 3 1 2 2 1 3 1 ... |
correct output |
---|
5 |
user output |
---|
(empty) |
Test 19
Group: 2, 6
Verdict: RUNTIME ERROR
input |
---|
7 28571 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ... |
correct output |
---|
3 |
user output |
---|
(empty) |
Test 20
Group: 2, 6
Verdict: RUNTIME ERROR
input |
---|
28571 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 ... |
correct output |
---|
5 |
user output |
---|
(empty) |
Test 21
Group: 2, 6
Verdict: ACCEPTED
input |
---|
447 447 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 ... |
correct output |
---|
3 |
user output |
---|
3 |
Test 22
Group: 3, 4, 5, 6
Verdict: WRONG ANSWER
input |
---|
1 100 46 23 23 55 37 17 30 32 25 71 ... |
correct output |
---|
30 |
user output |
---|
100 |
Test 23
Group: 3, 4, 5, 6
Verdict: WRONG ANSWER
input |
---|
1 100 8 13 12 11 15 15 15 19 18 21 2... |
correct output |
---|
76 |
user output |
---|
100 |
Test 24
Group: 3, 4, 5, 6
Verdict: WRONG ANSWER
input |
---|
1 100 94 94 94 95 95 91 97 100 92 98... |
correct output |
---|
95 |
user output |
---|
100 |
Test 25
Group: 3, 4, 5, 6
Verdict: WRONG ANSWER
input |
---|
1 100 83 83 83 83 83 83 83 83 83 83 ... |
correct output |
---|
83 |
user output |
---|
100 |
Test 26
Group: 3, 4, 5, 6
Verdict: WRONG ANSWER
input |
---|
1 100 33 34 35 38 38 40 41 42 42 45 ... |
correct output |
---|
95 |
user output |
---|
100 |
Test 27
Group: 3, 4, 5, 6
Verdict: WRONG ANSWER
input |
---|
1 100 57 1 80 39 18 63 30 86 85 55 8... |
correct output |
---|
29 |
user output |
---|
100 |
Test 28
Group: 4, 6
Verdict: RUNTIME ERROR
input |
---|
1 200000 138736 14949 12344 104147 1333... |
correct output |
---|
1806 |
user output |
---|
(empty) |
Test 29
Group: 4, 6
Verdict: RUNTIME ERROR
input |
---|
1 200000 141245 141090 141163 141286 14... |
correct output |
---|
155109 |
user output |
---|
(empty) |
Test 30
Group: 4, 6
Verdict: RUNTIME ERROR
input |
---|
1 200000 102358 102469 102440 102402 10... |
correct output |
---|
152388 |
user output |
---|
(empty) |
Test 31
Group: 4, 6
Verdict: RUNTIME ERROR
input |
---|
1 200000 180410 160820 160820 180614 18... |
correct output |
---|
160832 |
user output |
---|
(empty) |
Test 32
Group: 4, 6
Verdict: RUNTIME ERROR
input |
---|
1 200000 198270 198270 198270 198270 19... |
correct output |
---|
198270 |
user output |
---|
(empty) |
Test 33
Group: 4, 6
Verdict: RUNTIME ERROR
input |
---|
1 200000 1 1 3 2 1 1 2 3 6 6 6 7 8 9 10... |
correct output |
---|
199995 |
user output |
---|
(empty) |
Test 34
Group: 4, 6
Verdict: RUNTIME ERROR
input |
---|
1 200000 14737 162555 44228 170991 1340... |
correct output |
---|
1902 |
user output |
---|
(empty) |
Test 35
Group: 5, 6
Verdict: RUNTIME ERROR
input |
---|
31 32 669 792 226 189 860 737 291 83... |
correct output |
---|
565 |
user output |
---|
(empty) |
Error:
code: malloc.c:2617: sysmalloc: Assertion `(old_top == initial_top (av) && old_size == 0)...
Test 36
Group: 5, 6
Verdict: RUNTIME ERROR
input |
---|
10 100 730 698 339 743 536 702 94 556... |
correct output |
---|
529 |
user output |
---|
(empty) |
Error:
code: malloc.c:2617: sysmalloc: Assertion `(old_top == initial_top (av) && old_size == 0)...
Test 37
Group: 5, 6
Verdict: RUNTIME ERROR
input |
---|
32 31 633 613 618 605 635 638 668 67... |
correct output |
---|
678 |
user output |
---|
(empty) |
Error:
code: malloc.c:2617: sysmalloc: Assertion `(old_top == initial_top (av) && old_size == 0)...
Test 38
Group: 5, 6
Verdict: RUNTIME ERROR
input |
---|
142 7 983 930 963 926 979 962 962 966 930 963 924 928 928 926 926 929 929 922 931 931 978 929 929 929 922 959 928 964 ... |
correct output |
---|
934 |
user output |
---|
(empty) |
Error:
code: malloc.c:2617: sysmalloc: Assertion `(old_top == initial_top (av) && old_size == 0)...
Test 39
Group: 5, 6
Verdict: RUNTIME ERROR
input |
---|
31 32 977 977 977 977 977 977 977 97... |
correct output |
---|
977 |
user output |
---|
(empty) |
Error:
code: malloc.c:2617: sysmalloc: Assertion `(old_top == initial_top (av) && old_size == 0)...
Test 40
Group: 5, 6
Verdict: RUNTIME ERROR
input |
---|
50 20 1 27 14 23 38 48 56 3 12 9 6 2... |
correct output |
---|
997 |
user output |
---|
(empty) |
Error:
code: malloc.c:2617: sysmalloc: Assertion `(old_top == initial_top (av) && old_size == 0)...
Test 41
Group: 5, 6
Verdict: RUNTIME ERROR
input |
---|
20 50 481 532 624 290 965 58 448 872... |
correct output |
---|
504 |
user output |
---|
(empty) |
Error:
code: malloc.c:2617: sysmalloc: Assertion `(old_top == initial_top (av) && old_size == 0)...
Test 42
Group: 6
Verdict: TIME LIMIT EXCEEDED
input |
---|
447 447 6474 27185 108482 124481 16058... |
correct output |
---|
88202 |
user output |
---|
(empty) |
Test 43
Group: 6
Verdict: RUNTIME ERROR
input |
---|
1000 200 27722 57131 197677 184858 9285... |
correct output |
---|
89324 |
user output |
---|
(empty) |
Test 44
Group: 6
Verdict: ACCEPTED
input |
---|
447 447 70928 73154 72640 74764 75237 ... |
correct output |
---|
181096 |
user output |
---|
181096 |
Test 45
Group: 6
Verdict: RUNTIME ERROR
input |
---|
7 28571 193031 185883 171670 185794 17... |
correct output |
---|
171680 |
user output |
---|
(empty) |
Test 46
Group: 6
Verdict: RUNTIME ERROR
input |
---|
10 20000 191628 191628 191628 191628 19... |
correct output |
---|
191628 |
user output |
---|
(empty) |
Test 47
Group: 6
Verdict: RUNTIME ERROR
input |
---|
200 1000 3550 2640 3791 4248 4257 4504 ... |
correct output |
---|
199997 |
user output |
---|
(empty) |
Test 48
Group: 6
Verdict: RUNTIME ERROR
input |
---|
1000 200 198379 62425 88013 50967 49098... |
correct output |
---|
89131 |
user output |
---|
(empty) |