# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
67591 |
2018-08-15T05:07:01 Z |
Crown |
Wombats (IOI13_wombats) |
C++14 |
|
20000 ms |
208336 KB |
#include "wombats.h"
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define pb push_back
typedef pair<int, int> ii;
typedef long long ll;
int n, m;
const int maxn = 5005;
const int maxm = 205;
int H[maxn][maxm], V[maxn][maxm];
struct node
{
vector< vector<int> > dist;
node(){}
node(bool create)
{
if(create)
{
dist.assign(m, vector<int>(m, 1e9));
for(int i = 0; i< m; i++) dist[i][i] = 0;
}
}
};
node st[4*maxn];
const int ub = 15;
void dijk(int s, int r1, int r2, vector<int> &dist)
{
vector<vector<int> > tod(r2-r1+1, vector<int>(m, 1e9));
tod[0][s] = 0;
priority_queue< pair<int, ii> > pq;
pq.push(make_pair(0, ii(r1, s)));
while(!pq.empty())
{
auto f = pq.top(); pq.pop();
int d = -f.X, x = f.Y.X, y = f.Y.Y;
if(d> tod[x-r1][y]) continue;
if(y && H[x][y-1]+d< tod[x-r1][y-1])
{
tod[x-r1][y-1] = H[x][y-1]+d;
pq.push(make_pair(-tod[x-r1][y-1], ii(x, y-1)));
}
if(y+1< m && H[x][y]+d< tod[x-r1][y+1])
{
tod[x-r1][y+1] = H[x][y]+d;
pq.push(make_pair(-tod[x-r1][y+1], ii(x, y+1)));
}
if(x+1<= r2 && V[x][y]+d< tod[x+1-r1][y])
{
tod[x+1-r1][y] = V[x][y]+d;
pq.push(make_pair(-tod[x+1-r1][y], ii(x+1, y)));
}
}
dist = tod.back();
}
void merge(vector< vector<int> > &dist, vector< vector<int> > &d1, vector< vector<int> > &d2)
{
// printf("begun merging\n");
vector< vector<int> > opt(m, vector<int>(m, 0));
for(int diff = -m+1; diff<= m-1; diff++)
{
for(int i = 0; i< m; i++)
{
int j = i+diff;
if(j< 0 || j>= m) continue;
// printf("begun %d %d\n", i, j);
dist[i][j] = 1e9;
if(diff == -m+1)
{
for(int k = 0; k< m; k++)
{
if(d1[i][k]+d2[k][j]< dist[i][j])
{
dist[i][j] = d1[i][k] + d2[k][j];
opt[i][j] = k;
}
}
}
else
{
for(int k = max(0, j?opt[i][j-1]:0); k<= min(m-1, i+1< m?opt[i+1][j]:m-1); k++)
{
//printf("k = %d\n", k);
if(d1[i][k]+d2[k][j]< dist[i][j])
{
dist[i][j] = d1[i][k] + d2[k][j];
opt[i][j] = k;
}
}
}
}
}
// printf("finished merging\n");
}
void build(int p = 1, int L = 0, int R = n-1)
{
// printf("%d %d %d\n", p, L, R);
st[p] = node(true);
if(R-L+1<= ub)
{
for(int i = 0; i< m; i++)
{
dijk(i, L, R, st[p].dist[i]);
}
// printf("finished creating\n");
return;
}
build(2*p, L, (L+R)/2);
build(2*p+1, (L+R)/2, R);
merge(st[p].dist, st[2*p].dist, st[2*p+1].dist);
}
void update(int x, int p = 1, int L = 0, int R = n-1)
{
if(R-L+1<= ub)
{
for(int i = 0; i< m; i++)
{
dijk(i, L, R, st[p].dist[i]);
}
return;
}
int M = (L+R)/2;
if(x<= M) update(x, 2*p, L, (L+R)/2);
if(M<= x) update(x, 2*p+1, (L+R)/2, R);
merge(st[p].dist, st[2*p].dist, st[2*p+1].dist);
}
void init(int R, int C, int h[5000][200], int v[5000][200])
{
n = R, m = C;
for(int i = 0; i< n; i++)
{
for(int j = 0; j+1< m; j++)
{
H[i][j] = h[i][j];
}
}
for(int i = 0; i+1< n; i++)
{
for(int j = 0; j< m; j++)
{
V[i][j] = v[i][j];
}
}
//printf("started initing\n");
build();
}
void changeH(int P, int Q, int W)
{
//printf("changingH\n");
H[P][Q] = W;
update(P);
}
void changeV(int P, int Q, int W)
{
//printf("changingV\n");
V[P][Q] = W;
update(P);
}
int escape(int V1, int V2)
{
return st[1].dist[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 |
11 ms |
8696 KB |
Output is correct |
2 |
Correct |
12 ms |
8936 KB |
Output is correct |
3 |
Correct |
97 ms |
10488 KB |
Output is correct |
4 |
Correct |
14 ms |
10488 KB |
Output is correct |
5 |
Correct |
10 ms |
10488 KB |
Output is correct |
6 |
Correct |
2 ms |
10488 KB |
Output is correct |
7 |
Correct |
3 ms |
10488 KB |
Output is correct |
8 |
Correct |
2 ms |
10488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
10488 KB |
Output is correct |
2 |
Correct |
2 ms |
10488 KB |
Output is correct |
3 |
Correct |
3 ms |
10488 KB |
Output is correct |
4 |
Correct |
4 ms |
10488 KB |
Output is correct |
5 |
Correct |
4 ms |
10488 KB |
Output is correct |
6 |
Correct |
4 ms |
10488 KB |
Output is correct |
7 |
Correct |
5 ms |
10488 KB |
Output is correct |
8 |
Correct |
4 ms |
10488 KB |
Output is correct |
9 |
Correct |
4 ms |
10488 KB |
Output is correct |
10 |
Correct |
4 ms |
10488 KB |
Output is correct |
11 |
Correct |
80 ms |
10488 KB |
Output is correct |
12 |
Correct |
5 ms |
10488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1688 ms |
10488 KB |
Output is correct |
2 |
Correct |
3191 ms |
10488 KB |
Output is correct |
3 |
Correct |
1803 ms |
10488 KB |
Output is correct |
4 |
Correct |
1704 ms |
10488 KB |
Output is correct |
5 |
Correct |
1813 ms |
10488 KB |
Output is correct |
6 |
Correct |
3 ms |
10488 KB |
Output is correct |
7 |
Correct |
3 ms |
10488 KB |
Output is correct |
8 |
Correct |
2 ms |
10488 KB |
Output is correct |
9 |
Correct |
15752 ms |
10488 KB |
Output is correct |
10 |
Correct |
3 ms |
10488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
18976 KB |
Output is correct |
2 |
Correct |
23 ms |
18992 KB |
Output is correct |
3 |
Correct |
27 ms |
19180 KB |
Output is correct |
4 |
Correct |
70 ms |
20528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1736 ms |
20528 KB |
Output is correct |
2 |
Correct |
3215 ms |
20528 KB |
Output is correct |
3 |
Correct |
1746 ms |
20528 KB |
Output is correct |
4 |
Correct |
1688 ms |
20528 KB |
Output is correct |
5 |
Correct |
1835 ms |
20528 KB |
Output is correct |
6 |
Correct |
32 ms |
20528 KB |
Output is correct |
7 |
Correct |
22 ms |
20528 KB |
Output is correct |
8 |
Correct |
25 ms |
20528 KB |
Output is correct |
9 |
Correct |
66 ms |
21688 KB |
Output is correct |
10 |
Correct |
12 ms |
21688 KB |
Output is correct |
11 |
Correct |
12 ms |
21688 KB |
Output is correct |
12 |
Correct |
81 ms |
21688 KB |
Output is correct |
13 |
Correct |
15 ms |
21688 KB |
Output is correct |
14 |
Correct |
13 ms |
21688 KB |
Output is correct |
15 |
Correct |
3 ms |
21688 KB |
Output is correct |
16 |
Correct |
2 ms |
21688 KB |
Output is correct |
17 |
Correct |
2 ms |
21688 KB |
Output is correct |
18 |
Correct |
5 ms |
21688 KB |
Output is correct |
19 |
Correct |
4 ms |
21688 KB |
Output is correct |
20 |
Correct |
5 ms |
21688 KB |
Output is correct |
21 |
Correct |
5 ms |
21688 KB |
Output is correct |
22 |
Correct |
5 ms |
21688 KB |
Output is correct |
23 |
Correct |
5 ms |
21688 KB |
Output is correct |
24 |
Correct |
5 ms |
21688 KB |
Output is correct |
25 |
Correct |
138 ms |
21688 KB |
Output is correct |
26 |
Correct |
5 ms |
21688 KB |
Output is correct |
27 |
Correct |
15616 ms |
21688 KB |
Output is correct |
28 |
Execution timed out |
20008 ms |
72000 KB |
Time limit exceeded |
29 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1759 ms |
72000 KB |
Output is correct |
2 |
Correct |
3293 ms |
72000 KB |
Output is correct |
3 |
Correct |
1756 ms |
72000 KB |
Output is correct |
4 |
Correct |
1712 ms |
72000 KB |
Output is correct |
5 |
Correct |
1746 ms |
72000 KB |
Output is correct |
6 |
Correct |
22 ms |
72000 KB |
Output is correct |
7 |
Correct |
23 ms |
72000 KB |
Output is correct |
8 |
Correct |
21 ms |
72000 KB |
Output is correct |
9 |
Correct |
70 ms |
72000 KB |
Output is correct |
10 |
Correct |
12 ms |
72000 KB |
Output is correct |
11 |
Correct |
12 ms |
72000 KB |
Output is correct |
12 |
Correct |
106 ms |
72000 KB |
Output is correct |
13 |
Correct |
13 ms |
72000 KB |
Output is correct |
14 |
Correct |
15 ms |
72000 KB |
Output is correct |
15 |
Correct |
16638 ms |
208336 KB |
Output is correct |
16 |
Execution timed out |
20081 ms |
208336 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |