# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1036412 | 2024-07-27T10:41:45 Z | beaconmc | Wiring (IOI17_wiring) | C++14 | 518 ms | 115380 KB |
#include "wiring.h" #include <bits/stdc++.h> typedef long long ll; #define FOR(i,x,y) for(ll i=x; i<y; i++) #define FORNEG(i,x,y) for(ll i=x; i>y; i--) using namespace std; ll n,m; vector<ll> R,B; unordered_map<int,ll> cache; unordered_map<int,ll> poses; bool flag; ll dp(ll x, ll y){ if (flag && abs(poses[R[x]]-poses[B[y]]) > 20) return 1000000000000000; if (cache.count(x*1000000+y)) return cache[x*1000000+y]; if (x==n && y==m) return 0; if (x>=n || y >= m) return 1000000000000000; return cache[x*1000000+y] = min(dp(x+1,y), min(dp(x,y+1), dp(x+1,y+1))) + abs(R[x] - B[y]); } long long min_total_length(std::vector<int> r, std::vector<int> b) { if (r[r.size()-1] < b[0]){ while (r.size() > b.size()){ b.push_back(b[0]); } while (r.size() < b.size()){ r.push_back(r[r.size()-1]); } ll sumr=0,sumb=0; for(auto&i : r) sumr += i; for (auto&i : b) sumb += i; return sumb - sumr; } R.clear(); B.clear(); vector<ll> stuff; for (auto&i : r) stuff.push_back(i); for (auto&i : b) stuff.push_back(i); flag = false; if (r.size() > 200 || b.size() > 200) flag = true; sort(stuff.begin(), stuff.end()); FOR(i,0,stuff.size()){ poses[stuff[i]] = i; } cache.clear(); for (auto&i : r) R.push_back(i); for (auto&i : b) B.push_back(i); n = r.size(); m = b.size(); return dp(0,0); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 4 ms | 1972 KB | Output is correct |
8 | Correct | 3 ms | 1976 KB | Output is correct |
9 | Correct | 3 ms | 1976 KB | Output is correct |
10 | Correct | 3 ms | 1976 KB | Output is correct |
11 | Correct | 4 ms | 1976 KB | Output is correct |
12 | Correct | 4 ms | 1976 KB | Output is correct |
13 | Correct | 4 ms | 1976 KB | Output is correct |
14 | Correct | 3 ms | 1920 KB | Output is correct |
15 | Correct | 4 ms | 1976 KB | Output is correct |
16 | Correct | 4 ms | 1976 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 11 ms | 1804 KB | Output is correct |
4 | Correct | 12 ms | 3476 KB | Output is correct |
5 | Correct | 12 ms | 3480 KB | Output is correct |
6 | Correct | 16 ms | 4148 KB | Output is correct |
7 | Correct | 16 ms | 4188 KB | Output is correct |
8 | Correct | 17 ms | 3904 KB | Output is correct |
9 | Correct | 16 ms | 3676 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 517 ms | 109608 KB | Output is correct |
4 | Correct | 518 ms | 115380 KB | Output is correct |
5 | Correct | 1 ms | 344 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 0 ms | 348 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Correct | 0 ms | 348 KB | Output is correct |
12 | Correct | 0 ms | 344 KB | Output is correct |
13 | Correct | 1 ms | 344 KB | Output is correct |
14 | Correct | 0 ms | 348 KB | Output is correct |
15 | Correct | 1 ms | 604 KB | Output is correct |
16 | Correct | 1 ms | 604 KB | Output is correct |
17 | Correct | 1 ms | 604 KB | Output is correct |
18 | Correct | 495 ms | 109404 KB | Output is correct |
19 | Correct | 502 ms | 109488 KB | Output is correct |
20 | Correct | 509 ms | 115304 KB | Output is correct |
21 | Correct | 497 ms | 109236 KB | Output is correct |
22 | Correct | 497 ms | 110004 KB | Output is correct |
23 | Correct | 480 ms | 109680 KB | Output is correct |
24 | Correct | 469 ms | 109748 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Incorrect | 33 ms | 14968 KB | 3rd lines differ - on the 1st token, expected: '373710605', found: '1000000000000000' |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 4 ms | 1972 KB | Output is correct |
8 | Correct | 3 ms | 1976 KB | Output is correct |
9 | Correct | 3 ms | 1976 KB | Output is correct |
10 | Correct | 3 ms | 1976 KB | Output is correct |
11 | Correct | 4 ms | 1976 KB | Output is correct |
12 | Correct | 4 ms | 1976 KB | Output is correct |
13 | Correct | 4 ms | 1976 KB | Output is correct |
14 | Correct | 3 ms | 1920 KB | Output is correct |
15 | Correct | 4 ms | 1976 KB | Output is correct |
16 | Correct | 4 ms | 1976 KB | Output is correct |
17 | Correct | 0 ms | 348 KB | Output is correct |
18 | Correct | 0 ms | 348 KB | Output is correct |
19 | Correct | 11 ms | 1804 KB | Output is correct |
20 | Correct | 12 ms | 3476 KB | Output is correct |
21 | Correct | 12 ms | 3480 KB | Output is correct |
22 | Correct | 16 ms | 4148 KB | Output is correct |
23 | Correct | 16 ms | 4188 KB | Output is correct |
24 | Correct | 17 ms | 3904 KB | Output is correct |
25 | Correct | 16 ms | 3676 KB | Output is correct |
26 | Correct | 0 ms | 348 KB | Output is correct |
27 | Correct | 0 ms | 348 KB | Output is correct |
28 | Correct | 517 ms | 109608 KB | Output is correct |
29 | Correct | 518 ms | 115380 KB | Output is correct |
30 | Correct | 1 ms | 344 KB | Output is correct |
31 | Correct | 0 ms | 348 KB | Output is correct |
32 | Correct | 0 ms | 348 KB | Output is correct |
33 | Correct | 0 ms | 348 KB | Output is correct |
34 | Correct | 0 ms | 348 KB | Output is correct |
35 | Correct | 0 ms | 348 KB | Output is correct |
36 | Correct | 0 ms | 348 KB | Output is correct |
37 | Correct | 0 ms | 344 KB | Output is correct |
38 | Correct | 1 ms | 344 KB | Output is correct |
39 | Correct | 0 ms | 348 KB | Output is correct |
40 | Correct | 1 ms | 604 KB | Output is correct |
41 | Correct | 1 ms | 604 KB | Output is correct |
42 | Correct | 1 ms | 604 KB | Output is correct |
43 | Correct | 495 ms | 109404 KB | Output is correct |
44 | Correct | 502 ms | 109488 KB | Output is correct |
45 | Correct | 509 ms | 115304 KB | Output is correct |
46 | Correct | 497 ms | 109236 KB | Output is correct |
47 | Correct | 497 ms | 110004 KB | Output is correct |
48 | Correct | 480 ms | 109680 KB | Output is correct |
49 | Correct | 469 ms | 109748 KB | Output is correct |
50 | Correct | 0 ms | 344 KB | Output is correct |
51 | Incorrect | 33 ms | 14968 KB | 3rd lines differ - on the 1st token, expected: '373710605', found: '1000000000000000' |
52 | Halted | 0 ms | 0 KB | - |