# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
718867 |
2023-04-05T03:06:48 Z |
lam |
Saveit (IOI10_saveit) |
C++14 |
|
227 ms |
10240 KB |
#include "grader.h"
#include "encoder.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1010;
int n;
int par[maxn];
int d[36][maxn];
vector <int> adj[maxn];
void bfs(int rt, bool keep)
{
queue<int> q;
fill_n(d[rt],n,-1);
d[rt][rt] = 0;
q.push(rt);
if (keep) par[rt] = rt;
while (!q.empty())
{
int u=q.front(); q.pop();
for (int v:adj[u])
if (d[rt][v] == -1)
{
d[rt][v] = d[rt][u] + 1;
if (keep) par[v] = u;
q.push(v);
}
}
}
inline bool checkbit(int i, int j)
{
return i>>j&1;
}
void encode(int nv, int nh, int ne, int *v1, int *v2){
n=nv;
for (int i=0; i<n; i++) adj[i].clear();
for (int i=0; i<ne; i++)
{
int u=v1[i]; int v=v2[i];
adj[u].push_back(v);
adj[v].push_back(u);
}
for (int i=0; i<nh; i++) bfs(i,(i==0));
for (int i=0; i<n; i++)
{
for (int j=0; j<10; j++)
{
// cerr<<i<<' '<<j<<' '<<par[i]<<" : "<<checkbit(par[i],j)<<endl;
encode_bit(checkbit(par[i],j));
}
}
// for (int i=0; i<n; i++) cerr<<d[0][i]<<" : "; cerr<<endl;
// for (int i=0; i<n; i++) cerr<<d[1][i]<<" : "; cerr<<endl;
par[n]=par[n+1]=par[n+2]=0;
for (int rt=1; rt<nh; rt++)
for (int i=1; i<n; i+=3)
{
int u,v;
u=i; v=par[i];
// cerr<<u<<" - "<<v<<endl;
int t1 = (d[rt][u]==d[rt][v])?0:((d[rt][u]>d[rt][v])?1:2);
u=i+1; v=par[i+1];
int t2 = (d[rt][u]==d[rt][v])?0:((d[rt][u]>d[rt][v])?1:2);
u=i+2; v=par[i+2];
int t3 = (d[rt][u]==d[rt][v])?0:((d[rt][u]>d[rt][v])?1:2);
int T = t1+t2*3+t3*9;
// cerr<<t1<<" & "<<t2<<" & "<<t3<<endl;
for (int z=0; z<5; z++) encode_bit(checkbit(T,z));
}
}
#include "grader.h"
#include "decoder.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1010;
int _n,_rt;
vector <int> _adj[maxn];
int _par[maxn];
int _d[maxn],_t[maxn],_ans[maxn];
void _BFS()
{
queue<int> q;
fill_n(_d,_n,-1);
_d[0] = 0;
q.push(0);
while (!q.empty())
{
int u=q.front(); q.pop();
for (int v:_adj[u])
if (_d[v]==-1)
{
_d[v]=_d[u]+1;
q.push(v);
}
}
}
void dfs(int x, int p)
{
for (int i:_adj[x])
if (i!=p)
{
if (_t[i]==0) _ans[i]=_ans[x];
else if (_t[i]==1) _ans[i]=_ans[x]+1;
else _ans[i]=_ans[x]-1;
dfs(i,x);
}
}
void decode(int nv, int nh) {
_n=nv; _rt = 0;
// cerr<<nv<<' '<<nh<<endl;
for (int i=0; i<_n; i++)
{
int x=0;
for (int j=0; j<10; j++) if (decode_bit()) x|=(1<<j);
_par[i] = x;
_adj[_par[i]].push_back(i);
// cerr<<_par[i]<<" -> "<<i<<endl;
}
_BFS();
// for (int i=0; i<_n; i++) cerr<<_d[i]<<' '; cerr<<endl;
for (int i=0; i<_n; i++) hops(_rt,i,_d[i]);
for (int st = 1; st<nh; st++)
{
// cerr<<st<<endl;
for (int i=1; i<_n; i+=3)
{
int T = 0;
for (int z=0; z<5; z++) if (decode_bit()) T |= (1<<z);
int t1 = T%3; T/=3;
int t2 = T%3; T/=3;
int t3 = T%3; T/=3;
_t[i]=t1; _t[i+1]=t2; _t[i+2]=t3;
}
// for (int i=1; i<_n; i++) cerr<<_t[i]<<' '; cerr<<endl;
_ans[0] = _d[st];
dfs(0,0);
// for (int i=0; i<_n; i++) cerr<<_ans[i]<<' '; cerr<<endl;
for (int i=0; i<_n; i++) hops(st,i,_ans[i]);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
227 ms |
10240 KB |
Output is correct - 68275 call(s) of encode_bit() |
2 |
Correct |
2 ms |
4612 KB |
Output is correct - 70 call(s) of encode_bit() |
3 |
Correct |
20 ms |
5484 KB |
Output is correct - 61500 call(s) of encode_bit() |
4 |
Correct |
3 ms |
4604 KB |
Output is correct - 90 call(s) of encode_bit() |
5 |
Correct |
23 ms |
5620 KB |
Output is correct - 61500 call(s) of encode_bit() |
6 |
Correct |
25 ms |
5608 KB |
Output is correct - 68275 call(s) of encode_bit() |
7 |
Correct |
40 ms |
5920 KB |
Output is correct - 68275 call(s) of encode_bit() |
8 |
Correct |
24 ms |
5352 KB |
Output is correct - 65610 call(s) of encode_bit() |
9 |
Correct |
20 ms |
5628 KB |
Output is correct - 68275 call(s) of encode_bit() |
10 |
Correct |
26 ms |
5744 KB |
Output is correct - 68275 call(s) of encode_bit() |
11 |
Correct |
25 ms |
5744 KB |
Output is correct - 68275 call(s) of encode_bit() |
12 |
Correct |
19 ms |
5500 KB |
Output is correct - 68275 call(s) of encode_bit() |
13 |
Correct |
39 ms |
6192 KB |
Output is correct - 68275 call(s) of encode_bit() |
14 |
Correct |
23 ms |
5600 KB |
Output is correct - 68275 call(s) of encode_bit() |
15 |
Correct |
27 ms |
5636 KB |
Output is correct - 68275 call(s) of encode_bit() |
16 |
Correct |
47 ms |
6048 KB |
Output is correct - 68275 call(s) of encode_bit() |
17 |
Correct |
35 ms |
6048 KB |
Output is correct - 68275 call(s) of encode_bit() |
18 |
Correct |
43 ms |
6244 KB |
Output is correct - 68275 call(s) of encode_bit() |
19 |
Correct |
34 ms |
5700 KB |
Output is correct - 68275 call(s) of encode_bit() |
20 |
Correct |
54 ms |
6424 KB |
Output is correct - 68275 call(s) of encode_bit() |
21 |
Correct |
81 ms |
6676 KB |
Output is correct - 68275 call(s) of encode_bit() |
22 |
Correct |
37 ms |
6128 KB |
Output is correct - 68275 call(s) of encode_bit() |
23 |
Correct |
63 ms |
6708 KB |
Output is correct - 68275 call(s) of encode_bit() |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
227 ms |
10240 KB |
Output is correct - 68275 call(s) of encode_bit() |
2 |
Correct |
2 ms |
4612 KB |
Output is correct - 70 call(s) of encode_bit() |
3 |
Correct |
20 ms |
5484 KB |
Output is correct - 61500 call(s) of encode_bit() |
4 |
Correct |
3 ms |
4604 KB |
Output is correct - 90 call(s) of encode_bit() |
5 |
Correct |
23 ms |
5620 KB |
Output is correct - 61500 call(s) of encode_bit() |
6 |
Correct |
25 ms |
5608 KB |
Output is correct - 68275 call(s) of encode_bit() |
7 |
Correct |
40 ms |
5920 KB |
Output is correct - 68275 call(s) of encode_bit() |
8 |
Correct |
24 ms |
5352 KB |
Output is correct - 65610 call(s) of encode_bit() |
9 |
Correct |
20 ms |
5628 KB |
Output is correct - 68275 call(s) of encode_bit() |
10 |
Correct |
26 ms |
5744 KB |
Output is correct - 68275 call(s) of encode_bit() |
11 |
Correct |
25 ms |
5744 KB |
Output is correct - 68275 call(s) of encode_bit() |
12 |
Correct |
19 ms |
5500 KB |
Output is correct - 68275 call(s) of encode_bit() |
13 |
Correct |
39 ms |
6192 KB |
Output is correct - 68275 call(s) of encode_bit() |
14 |
Correct |
23 ms |
5600 KB |
Output is correct - 68275 call(s) of encode_bit() |
15 |
Correct |
27 ms |
5636 KB |
Output is correct - 68275 call(s) of encode_bit() |
16 |
Correct |
47 ms |
6048 KB |
Output is correct - 68275 call(s) of encode_bit() |
17 |
Correct |
35 ms |
6048 KB |
Output is correct - 68275 call(s) of encode_bit() |
18 |
Correct |
43 ms |
6244 KB |
Output is correct - 68275 call(s) of encode_bit() |
19 |
Correct |
34 ms |
5700 KB |
Output is correct - 68275 call(s) of encode_bit() |
20 |
Correct |
54 ms |
6424 KB |
Output is correct - 68275 call(s) of encode_bit() |
21 |
Correct |
81 ms |
6676 KB |
Output is correct - 68275 call(s) of encode_bit() |
22 |
Correct |
37 ms |
6128 KB |
Output is correct - 68275 call(s) of encode_bit() |
23 |
Correct |
63 ms |
6708 KB |
Output is correct - 68275 call(s) of encode_bit() |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
227 ms |
10240 KB |
Output is correct - 68275 call(s) of encode_bit() |
2 |
Correct |
2 ms |
4612 KB |
Output is correct - 70 call(s) of encode_bit() |
3 |
Correct |
20 ms |
5484 KB |
Output is correct - 61500 call(s) of encode_bit() |
4 |
Correct |
3 ms |
4604 KB |
Output is correct - 90 call(s) of encode_bit() |
5 |
Correct |
23 ms |
5620 KB |
Output is correct - 61500 call(s) of encode_bit() |
6 |
Correct |
25 ms |
5608 KB |
Output is correct - 68275 call(s) of encode_bit() |
7 |
Correct |
40 ms |
5920 KB |
Output is correct - 68275 call(s) of encode_bit() |
8 |
Correct |
24 ms |
5352 KB |
Output is correct - 65610 call(s) of encode_bit() |
9 |
Correct |
20 ms |
5628 KB |
Output is correct - 68275 call(s) of encode_bit() |
10 |
Correct |
26 ms |
5744 KB |
Output is correct - 68275 call(s) of encode_bit() |
11 |
Correct |
25 ms |
5744 KB |
Output is correct - 68275 call(s) of encode_bit() |
12 |
Correct |
19 ms |
5500 KB |
Output is correct - 68275 call(s) of encode_bit() |
13 |
Correct |
39 ms |
6192 KB |
Output is correct - 68275 call(s) of encode_bit() |
14 |
Correct |
23 ms |
5600 KB |
Output is correct - 68275 call(s) of encode_bit() |
15 |
Correct |
27 ms |
5636 KB |
Output is correct - 68275 call(s) of encode_bit() |
16 |
Correct |
47 ms |
6048 KB |
Output is correct - 68275 call(s) of encode_bit() |
17 |
Correct |
35 ms |
6048 KB |
Output is correct - 68275 call(s) of encode_bit() |
18 |
Correct |
43 ms |
6244 KB |
Output is correct - 68275 call(s) of encode_bit() |
19 |
Correct |
34 ms |
5700 KB |
Output is correct - 68275 call(s) of encode_bit() |
20 |
Correct |
54 ms |
6424 KB |
Output is correct - 68275 call(s) of encode_bit() |
21 |
Correct |
81 ms |
6676 KB |
Output is correct - 68275 call(s) of encode_bit() |
22 |
Correct |
37 ms |
6128 KB |
Output is correct - 68275 call(s) of encode_bit() |
23 |
Correct |
63 ms |
6708 KB |
Output is correct - 68275 call(s) of encode_bit() |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
227 ms |
10240 KB |
Output is correct - 68275 call(s) of encode_bit() |
2 |
Correct |
2 ms |
4612 KB |
Output is correct - 70 call(s) of encode_bit() |
3 |
Correct |
20 ms |
5484 KB |
Output is correct - 61500 call(s) of encode_bit() |
4 |
Correct |
3 ms |
4604 KB |
Output is correct - 90 call(s) of encode_bit() |
5 |
Correct |
23 ms |
5620 KB |
Output is correct - 61500 call(s) of encode_bit() |
6 |
Correct |
25 ms |
5608 KB |
Output is correct - 68275 call(s) of encode_bit() |
7 |
Correct |
40 ms |
5920 KB |
Output is correct - 68275 call(s) of encode_bit() |
8 |
Correct |
24 ms |
5352 KB |
Output is correct - 65610 call(s) of encode_bit() |
9 |
Correct |
20 ms |
5628 KB |
Output is correct - 68275 call(s) of encode_bit() |
10 |
Correct |
26 ms |
5744 KB |
Output is correct - 68275 call(s) of encode_bit() |
11 |
Correct |
25 ms |
5744 KB |
Output is correct - 68275 call(s) of encode_bit() |
12 |
Correct |
19 ms |
5500 KB |
Output is correct - 68275 call(s) of encode_bit() |
13 |
Correct |
39 ms |
6192 KB |
Output is correct - 68275 call(s) of encode_bit() |
14 |
Correct |
23 ms |
5600 KB |
Output is correct - 68275 call(s) of encode_bit() |
15 |
Correct |
27 ms |
5636 KB |
Output is correct - 68275 call(s) of encode_bit() |
16 |
Correct |
47 ms |
6048 KB |
Output is correct - 68275 call(s) of encode_bit() |
17 |
Correct |
35 ms |
6048 KB |
Output is correct - 68275 call(s) of encode_bit() |
18 |
Correct |
43 ms |
6244 KB |
Output is correct - 68275 call(s) of encode_bit() |
19 |
Correct |
34 ms |
5700 KB |
Output is correct - 68275 call(s) of encode_bit() |
20 |
Correct |
54 ms |
6424 KB |
Output is correct - 68275 call(s) of encode_bit() |
21 |
Correct |
81 ms |
6676 KB |
Output is correct - 68275 call(s) of encode_bit() |
22 |
Correct |
37 ms |
6128 KB |
Output is correct - 68275 call(s) of encode_bit() |
23 |
Correct |
63 ms |
6708 KB |
Output is correct - 68275 call(s) of encode_bit() |