# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
566647 |
2022-05-22T14:04:37 Z |
RealSnake |
Saveit (IOI10_saveit) |
C++14 |
|
228 ms |
16304 KB |
#include "bits/stdc++.h"
using namespace std;
#include "grader.h"
#include "encoder.h"
void encode(int n, int h, int p, int a[], int b[]) {
vector<int> v[n];
for(int i = 0; i < p; i++) {
v[a[i]].push_back(b[i]);
v[b[i]].push_back(a[i]);
}
set<int> s;
s.insert(0);
int par[n] = {};
par[0] = 1;
vector<int> v2[n];
while(s.size()) {
int x = *s.begin();
s.erase(s.begin());
for(int i : v[x]) {
if(!par[i]) {
v2[x].push_back(i);
v2[i].push_back(x);
par[i] = x + 1;
s.insert(i);
}
}
}
for(int i = 0; i < n; i++)
sort(v2[i].begin(), v2[i].end());
for(int i = 1; i < n; i++) {
int x = par[i] - 1;
for(int j = 0; j < 10; j++)
encode_bit(((x & (1 << j)) > 0));
}
int ans[n][h];
for(int i = 0; i < n; i++) {
for(int j = 0; j < h; j++)
ans[i][j] = 1e9;
}
set<pair<int, pair<int, int>>> ss;
for(int i = 0; i < h; i++) {
ss.insert({0, {i, i}});
ans[i][i] = 0;
}
while(ss.size()) {
pair<int, pair<int, int>> p = *ss.begin();
ss.erase(ss.begin());
int x = p.second.first, hub = p.second.second;
int cost = p.first;
if(cost > ans[x][hub])
continue;
for(int i : v[x]) {
if(cost + 1 < ans[i][hub]) {
ans[i][hub] = cost + 1;
ss.insert({cost + 1, {i, hub}});
}
}
}
bool vis[n];
for(int i = 0; i < h; i++) {
for(int j = 0; j < n; j++)
vis[j] = 0;
s.insert(i);
vis[i] = 1;
while(s.size()) {
int x = *s.begin();
s.erase(s.begin());
for(int j : v2[x]) {
if(vis[j])
continue;
vis[j] = 1;
s.insert(j);
if(j <= i)
continue;
int dif = ans[j][i] - ans[x][i];
if(dif == 0)
encode_bit(0);
else {
encode_bit(1);
if(dif == 1)
encode_bit(1);
else
encode_bit(0);
}
}
}
}
}
#include "bits/stdc++.h"
using namespace std;
#include "grader.h"
#include "decoder.h"
void decode(int n, int h) {
vector<int> v[n];
for(int i = 1; i < n; i++) {
int x = 0;
for(int j = 0; j < 10; j++) {
if(decode_bit())
x += (1 << j);
}
v[x].push_back(i);
v[i].push_back(x);
}
for(int i = 0; i < n; i++)
sort(v[i].begin(), v[i].end());
int ans[n][n];
bool vis[n];
for(int i = 0; i < h; i++) {
for(int j = 0; j < n; j++)
vis[j] = 0;
ans[i][i] = 0;
set<int> s;
s.insert(i);
vis[i] = 1;
while(s.size()) {
int x = *s.begin();
s.erase(s.begin());
if(x >= i) {
hops(i, x, ans[x][i]);
if(x < h && x != i)
hops(x, i, ans[x][i]);
}
for(int j : v[x]) {
if(vis[j])
continue;
vis[j] = 1;
s.insert(j);
if(j <= i)
continue;
int dif = decode_bit();
if(dif) {
if(!decode_bit())
dif = -1;
}
ans[j][i] = ans[i][j] = ans[x][i] + dif;
}
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
228 ms |
16304 KB |
Output is correct - 63933 call(s) of encode_bit() |
2 |
Correct |
3 ms |
4600 KB |
Output is correct - 55 call(s) of encode_bit() |
3 |
Correct |
39 ms |
9808 KB |
Output is correct - 59420 call(s) of encode_bit() |
4 |
Correct |
1 ms |
4604 KB |
Output is correct - 55 call(s) of encode_bit() |
5 |
Correct |
38 ms |
10480 KB |
Output is correct - 56715 call(s) of encode_bit() |
6 |
Correct |
43 ms |
11372 KB |
Output is correct - 61501 call(s) of encode_bit() |
7 |
Correct |
56 ms |
11936 KB |
Output is correct - 51871 call(s) of encode_bit() |
8 |
Correct |
41 ms |
9316 KB |
Output is partially correct - 77460 call(s) of encode_bit() |
9 |
Correct |
34 ms |
9648 KB |
Output is partially correct - 79248 call(s) of encode_bit() |
10 |
Correct |
39 ms |
9632 KB |
Output is partially correct - 79063 call(s) of encode_bit() |
11 |
Correct |
44 ms |
9756 KB |
Output is partially correct - 77337 call(s) of encode_bit() |
12 |
Correct |
38 ms |
9504 KB |
Output is partially correct - 80658 call(s) of encode_bit() |
13 |
Correct |
72 ms |
11272 KB |
Output is correct - 59364 call(s) of encode_bit() |
14 |
Correct |
40 ms |
9688 KB |
Output is partially correct - 78099 call(s) of encode_bit() |
15 |
Correct |
45 ms |
9668 KB |
Output is partially correct - 75534 call(s) of encode_bit() |
16 |
Correct |
59 ms |
10136 KB |
Output is partially correct - 73551 call(s) of encode_bit() |
17 |
Correct |
53 ms |
10244 KB |
Output is partially correct - 73551 call(s) of encode_bit() |
18 |
Correct |
58 ms |
10684 KB |
Output is correct - 69229 call(s) of encode_bit() |
19 |
Correct |
47 ms |
10496 KB |
Output is correct - 64358 call(s) of encode_bit() |
20 |
Correct |
71 ms |
11636 KB |
Output is correct - 63152 call(s) of encode_bit() |
21 |
Correct |
79 ms |
11488 KB |
Output is correct - 64032 call(s) of encode_bit() |
22 |
Correct |
66 ms |
11820 KB |
Output is correct - 54501 call(s) of encode_bit() |
23 |
Correct |
84 ms |
12452 KB |
Output is correct - 56470 call(s) of encode_bit() |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
228 ms |
16304 KB |
Output is correct - 63933 call(s) of encode_bit() |
2 |
Correct |
3 ms |
4600 KB |
Output is correct - 55 call(s) of encode_bit() |
3 |
Correct |
39 ms |
9808 KB |
Output is correct - 59420 call(s) of encode_bit() |
4 |
Correct |
1 ms |
4604 KB |
Output is correct - 55 call(s) of encode_bit() |
5 |
Correct |
38 ms |
10480 KB |
Output is correct - 56715 call(s) of encode_bit() |
6 |
Correct |
43 ms |
11372 KB |
Output is correct - 61501 call(s) of encode_bit() |
7 |
Correct |
56 ms |
11936 KB |
Output is correct - 51871 call(s) of encode_bit() |
8 |
Correct |
41 ms |
9316 KB |
Output is partially correct - 77460 call(s) of encode_bit() |
9 |
Correct |
34 ms |
9648 KB |
Output is partially correct - 79248 call(s) of encode_bit() |
10 |
Correct |
39 ms |
9632 KB |
Output is partially correct - 79063 call(s) of encode_bit() |
11 |
Correct |
44 ms |
9756 KB |
Output is partially correct - 77337 call(s) of encode_bit() |
12 |
Correct |
38 ms |
9504 KB |
Output is partially correct - 80658 call(s) of encode_bit() |
13 |
Correct |
72 ms |
11272 KB |
Output is correct - 59364 call(s) of encode_bit() |
14 |
Correct |
40 ms |
9688 KB |
Output is partially correct - 78099 call(s) of encode_bit() |
15 |
Correct |
45 ms |
9668 KB |
Output is partially correct - 75534 call(s) of encode_bit() |
16 |
Correct |
59 ms |
10136 KB |
Output is partially correct - 73551 call(s) of encode_bit() |
17 |
Correct |
53 ms |
10244 KB |
Output is partially correct - 73551 call(s) of encode_bit() |
18 |
Correct |
58 ms |
10684 KB |
Output is correct - 69229 call(s) of encode_bit() |
19 |
Correct |
47 ms |
10496 KB |
Output is correct - 64358 call(s) of encode_bit() |
20 |
Correct |
71 ms |
11636 KB |
Output is correct - 63152 call(s) of encode_bit() |
21 |
Correct |
79 ms |
11488 KB |
Output is correct - 64032 call(s) of encode_bit() |
22 |
Correct |
66 ms |
11820 KB |
Output is correct - 54501 call(s) of encode_bit() |
23 |
Correct |
84 ms |
12452 KB |
Output is correct - 56470 call(s) of encode_bit() |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
228 ms |
16304 KB |
Output is correct - 63933 call(s) of encode_bit() |
2 |
Correct |
3 ms |
4600 KB |
Output is correct - 55 call(s) of encode_bit() |
3 |
Correct |
39 ms |
9808 KB |
Output is correct - 59420 call(s) of encode_bit() |
4 |
Correct |
1 ms |
4604 KB |
Output is correct - 55 call(s) of encode_bit() |
5 |
Correct |
38 ms |
10480 KB |
Output is correct - 56715 call(s) of encode_bit() |
6 |
Correct |
43 ms |
11372 KB |
Output is correct - 61501 call(s) of encode_bit() |
7 |
Correct |
56 ms |
11936 KB |
Output is correct - 51871 call(s) of encode_bit() |
8 |
Correct |
41 ms |
9316 KB |
Output is partially correct - 77460 call(s) of encode_bit() |
9 |
Correct |
34 ms |
9648 KB |
Output is partially correct - 79248 call(s) of encode_bit() |
10 |
Correct |
39 ms |
9632 KB |
Output is partially correct - 79063 call(s) of encode_bit() |
11 |
Correct |
44 ms |
9756 KB |
Output is partially correct - 77337 call(s) of encode_bit() |
12 |
Correct |
38 ms |
9504 KB |
Output is partially correct - 80658 call(s) of encode_bit() |
13 |
Correct |
72 ms |
11272 KB |
Output is correct - 59364 call(s) of encode_bit() |
14 |
Correct |
40 ms |
9688 KB |
Output is partially correct - 78099 call(s) of encode_bit() |
15 |
Correct |
45 ms |
9668 KB |
Output is partially correct - 75534 call(s) of encode_bit() |
16 |
Correct |
59 ms |
10136 KB |
Output is partially correct - 73551 call(s) of encode_bit() |
17 |
Correct |
53 ms |
10244 KB |
Output is partially correct - 73551 call(s) of encode_bit() |
18 |
Correct |
58 ms |
10684 KB |
Output is correct - 69229 call(s) of encode_bit() |
19 |
Correct |
47 ms |
10496 KB |
Output is correct - 64358 call(s) of encode_bit() |
20 |
Correct |
71 ms |
11636 KB |
Output is correct - 63152 call(s) of encode_bit() |
21 |
Correct |
79 ms |
11488 KB |
Output is correct - 64032 call(s) of encode_bit() |
22 |
Correct |
66 ms |
11820 KB |
Output is correct - 54501 call(s) of encode_bit() |
23 |
Correct |
84 ms |
12452 KB |
Output is correct - 56470 call(s) of encode_bit() |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
228 ms |
16304 KB |
Output is correct - 63933 call(s) of encode_bit() |
2 |
Correct |
3 ms |
4600 KB |
Output is correct - 55 call(s) of encode_bit() |
3 |
Correct |
39 ms |
9808 KB |
Output is correct - 59420 call(s) of encode_bit() |
4 |
Correct |
1 ms |
4604 KB |
Output is correct - 55 call(s) of encode_bit() |
5 |
Correct |
38 ms |
10480 KB |
Output is correct - 56715 call(s) of encode_bit() |
6 |
Correct |
43 ms |
11372 KB |
Output is correct - 61501 call(s) of encode_bit() |
7 |
Correct |
56 ms |
11936 KB |
Output is correct - 51871 call(s) of encode_bit() |
8 |
Correct |
41 ms |
9316 KB |
Output is partially correct - 77460 call(s) of encode_bit() |
9 |
Correct |
34 ms |
9648 KB |
Output is partially correct - 79248 call(s) of encode_bit() |
10 |
Correct |
39 ms |
9632 KB |
Output is partially correct - 79063 call(s) of encode_bit() |
11 |
Correct |
44 ms |
9756 KB |
Output is partially correct - 77337 call(s) of encode_bit() |
12 |
Correct |
38 ms |
9504 KB |
Output is partially correct - 80658 call(s) of encode_bit() |
13 |
Correct |
72 ms |
11272 KB |
Output is correct - 59364 call(s) of encode_bit() |
14 |
Correct |
40 ms |
9688 KB |
Output is partially correct - 78099 call(s) of encode_bit() |
15 |
Correct |
45 ms |
9668 KB |
Output is partially correct - 75534 call(s) of encode_bit() |
16 |
Correct |
59 ms |
10136 KB |
Output is partially correct - 73551 call(s) of encode_bit() |
17 |
Correct |
53 ms |
10244 KB |
Output is partially correct - 73551 call(s) of encode_bit() |
18 |
Correct |
58 ms |
10684 KB |
Output is correct - 69229 call(s) of encode_bit() |
19 |
Correct |
47 ms |
10496 KB |
Output is correct - 64358 call(s) of encode_bit() |
20 |
Correct |
71 ms |
11636 KB |
Output is correct - 63152 call(s) of encode_bit() |
21 |
Correct |
79 ms |
11488 KB |
Output is correct - 64032 call(s) of encode_bit() |
22 |
Correct |
66 ms |
11820 KB |
Output is correct - 54501 call(s) of encode_bit() |
23 |
Correct |
84 ms |
12452 KB |
Output is correct - 56470 call(s) of encode_bit() |