# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
60229 |
2018-07-23T22:02:20 Z |
ksun48 |
Wombats (IOI13_wombats) |
C++14 |
|
20000 ms |
21676 KB |
#include "wombats.h"
#include <bits/stdc++.h>
using namespace std;
typedef vector<vector<int> > Paths;
const int MAXD = 100000000; // 1e8
int r;
int c;
vector<vector<int> > h;
vector<vector<int> > v;
void pr(const Paths &ans){
for(int i = 0; i < c; i++){
for(int j = 0; j < c; j++){
cout << ans[i][j] << " ";
}
cout << endl;
}
cout << endl;
}
void dnc(const Paths &a, const Paths &b, Paths &paths, int t, int bl, int br, int ml, int mr){
if(bl > br) return;
// top, bottom left, bottom right
int bm = (bl + br) / 2;
int best = MAXD + 1;
int bestm = -1;
for(int m = ml; m <= mr; m++){
int dist = a[t][m] + b[m][bm];
if(dist < best){
best = dist;
bestm = m;
}
}
assert(bestm != -1);
paths[t][bm] = best;
dnc(a, b, paths, t, bl, bm - 1, ml, bestm);
dnc(a, b, paths, t, bm + 1, br, bestm, mr);
}
Paths join(const Paths &a, const Paths &b){
Paths paths(c, vector<int>(c, MAXD));
for(int i = 0; i < c; i++){
dnc(a, b, paths, i, 0, c-1, 0, c-1);
}
return paths;
}
Paths horizontal(int row){
vector<int> psums(c);
psums[0] = 0;
for(int i = 1; i < c; i++){
psums[i] = psums[i-1] + h[row][i-1];
}
Paths paths(c, vector<int>(c, MAXD));
for(int i = 0; i < c; i++){
for(int j = 0; j < c; j++){
paths[i][j] = abs(psums[j] - psums[i]);
}
}
return paths;
}
Paths empty(){
Paths p2(c, vector<int>(c, MAXD));
for(int i = 0; i < c; i++){
p2[i][i] = 0;
}
return p2;
}
Paths make(int row){
Paths p2(c, vector<int>(c, MAXD));
for(int i = 0; i < c; i++){
p2[i][i] = v[row][i];
}
return join(horizontal(row), join(p2, horizontal(row + 1)));
}
Paths ans;
int updated = 0;
void compute(){
ans = empty();
for(int i = 0; i + 1 < r; i++){
ans = join(ans, make(i));
}
updated = 1;
}
void init(int R, int C, int H[5000][200], int V[5000][200]) {
r = R;
c = C;
h.resize(r, vector<int>(c-1, 0));
v.resize(r-1, vector<int>(c, 0));
for(int i = 0; i < r; i++){
for(int j = 0; j < c-1; j++){
h[i][j] = H[i][j];
}
}
for(int i = 0; i < r-1; i++){
for(int j = 0; j < c; j++){
v[i][j] = V[i][j];
}
}
compute();
}
void changeH(int P, int Q, int W) {
h[P][Q] = W;
updated = 0;
}
void changeV(int P, int Q, int W) {
v[P][Q] = W;
updated = 0;
}
int escape(int V1, int V2) {
if(!updated){
compute();
}
return ans[V1][V2];
}
Compilation message
grader.c: In function 'int main()':
grader.c:15:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
int res;
^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2532 ms |
4656 KB |
Output is correct |
2 |
Correct |
2534 ms |
4708 KB |
Output is correct |
3 |
Correct |
2491 ms |
6272 KB |
Output is correct |
4 |
Correct |
2669 ms |
6272 KB |
Output is correct |
5 |
Correct |
2636 ms |
6272 KB |
Output is correct |
6 |
Correct |
2 ms |
6272 KB |
Output is correct |
7 |
Correct |
3 ms |
6272 KB |
Output is correct |
8 |
Correct |
3 ms |
6272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6272 KB |
Output is correct |
2 |
Correct |
2 ms |
6272 KB |
Output is correct |
3 |
Correct |
3 ms |
6272 KB |
Output is correct |
4 |
Correct |
4 ms |
6272 KB |
Output is correct |
5 |
Correct |
5 ms |
6272 KB |
Output is correct |
6 |
Correct |
5 ms |
6272 KB |
Output is correct |
7 |
Correct |
3 ms |
6272 KB |
Output is correct |
8 |
Correct |
4 ms |
6272 KB |
Output is correct |
9 |
Correct |
4 ms |
6272 KB |
Output is correct |
10 |
Correct |
3 ms |
6272 KB |
Output is correct |
11 |
Correct |
92 ms |
6272 KB |
Output is correct |
12 |
Correct |
6 ms |
6272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
765 ms |
6272 KB |
Output is correct |
2 |
Correct |
5065 ms |
6272 KB |
Output is correct |
3 |
Correct |
6503 ms |
6272 KB |
Output is correct |
4 |
Correct |
7135 ms |
6272 KB |
Output is correct |
5 |
Correct |
6734 ms |
6272 KB |
Output is correct |
6 |
Correct |
3 ms |
6272 KB |
Output is correct |
7 |
Correct |
2 ms |
6272 KB |
Output is correct |
8 |
Correct |
3 ms |
6272 KB |
Output is correct |
9 |
Correct |
2318 ms |
6272 KB |
Output is correct |
10 |
Correct |
4 ms |
6272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5048 ms |
9024 KB |
Output is correct |
2 |
Correct |
4207 ms |
9024 KB |
Output is correct |
3 |
Correct |
4046 ms |
9148 KB |
Output is correct |
4 |
Correct |
3832 ms |
9900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
831 ms |
9900 KB |
Output is correct |
2 |
Correct |
5193 ms |
9900 KB |
Output is correct |
3 |
Correct |
6031 ms |
9900 KB |
Output is correct |
4 |
Correct |
6056 ms |
9900 KB |
Output is correct |
5 |
Correct |
6102 ms |
9900 KB |
Output is correct |
6 |
Correct |
3540 ms |
9900 KB |
Output is correct |
7 |
Correct |
3523 ms |
9900 KB |
Output is correct |
8 |
Correct |
4003 ms |
9900 KB |
Output is correct |
9 |
Correct |
3861 ms |
9940 KB |
Output is correct |
10 |
Correct |
2412 ms |
9940 KB |
Output is correct |
11 |
Correct |
2460 ms |
9940 KB |
Output is correct |
12 |
Correct |
2578 ms |
9940 KB |
Output is correct |
13 |
Correct |
2431 ms |
9940 KB |
Output is correct |
14 |
Correct |
2376 ms |
9940 KB |
Output is correct |
15 |
Correct |
3 ms |
9940 KB |
Output is correct |
16 |
Correct |
3 ms |
9940 KB |
Output is correct |
17 |
Correct |
3 ms |
9940 KB |
Output is correct |
18 |
Correct |
3 ms |
9940 KB |
Output is correct |
19 |
Correct |
3 ms |
9940 KB |
Output is correct |
20 |
Correct |
3 ms |
9940 KB |
Output is correct |
21 |
Correct |
3 ms |
9940 KB |
Output is correct |
22 |
Correct |
3 ms |
9940 KB |
Output is correct |
23 |
Correct |
3 ms |
9940 KB |
Output is correct |
24 |
Correct |
3 ms |
9940 KB |
Output is correct |
25 |
Correct |
134 ms |
9940 KB |
Output is correct |
26 |
Correct |
6 ms |
9940 KB |
Output is correct |
27 |
Correct |
2558 ms |
9940 KB |
Output is correct |
28 |
Execution timed out |
20083 ms |
16980 KB |
Time limit exceeded |
29 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
691 ms |
16980 KB |
Output is correct |
2 |
Correct |
5532 ms |
16980 KB |
Output is correct |
3 |
Correct |
5841 ms |
16980 KB |
Output is correct |
4 |
Correct |
6827 ms |
16980 KB |
Output is correct |
5 |
Correct |
5828 ms |
16980 KB |
Output is correct |
6 |
Correct |
3837 ms |
16980 KB |
Output is correct |
7 |
Correct |
3842 ms |
16980 KB |
Output is correct |
8 |
Correct |
3482 ms |
16980 KB |
Output is correct |
9 |
Correct |
3672 ms |
16980 KB |
Output is correct |
10 |
Correct |
2201 ms |
16980 KB |
Output is correct |
11 |
Correct |
2537 ms |
16980 KB |
Output is correct |
12 |
Correct |
2274 ms |
16980 KB |
Output is correct |
13 |
Correct |
2377 ms |
16980 KB |
Output is correct |
14 |
Correct |
2418 ms |
16980 KB |
Output is correct |
15 |
Execution timed out |
20100 ms |
21676 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |