# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
566776 |
2022-05-22T20:33:04 Z |
shrimb |
Saveit (IOI10_saveit) |
C++17 |
|
220 ms |
14016 KB |
#include<bits/stdc++.h>
#include "grader.h"
#include "encoder.h"
using namespace std;
void encode(int n, int h, int p, int a[], int b[]){
vector<int>adj[n];
int dis[n],par[n];
for(int i = 0; i < n; i++) {
dis[i] = 1000000000;
}
for(int i = 0; i < p; i++){
adj[a[i]].push_back(b[i]);
adj[b[i]].push_back(a[i]);
}
memset(par, -1, sizeof par);
dis[0] = par[0] = 0;
vector<int>d = {0};
int j = 0;
while(j < d.size()){
for(auto s: adj[d[j]]){
if(dis[s] == 1000000000){
dis[s] = dis[d[j]] + 1;
par[s] = d[j];
d.push_back(s);
}
}
j++;
}
for(int i = 1; i < n; i++){
// if (par[i] == -1) assert(0);
for(int k = 0; k < 10; k++){
if(par[i] & (1 << k)) encode_bit(1);
else encode_bit(0);
}
}
for(int i = 1; i < h; i++){
vector<int>pc(n, 1000000000);
pc[i] = 0;
int j = 0;
vector<int>b = {i};
while(j < b.size()){
for(auto s:adj[b[j]]){
if(pc[s] == 1000000000){
pc[s] = pc[b[j]] + 1;
b.push_back(s);
}
}
j++;
}
for(int k = 1; k < n; k++){
int diff = pc[k] - pc[par[k]];
if(diff != 0){
encode_bit(1);
if(diff < 0) encode_bit(1);
else encode_bit(0);
}else{
encode_bit(0);
}
}
}
}
#include<bits/stdc++.h>
#include "grader.h"
#include "decoder.h"
using namespace std;
void decode(int n, int h){
int dis[n],p[n],j;
vector<int> diff[n];
vector<int>adj[n];
j = 0;
for(int i = 0; i < n; i++) {
diff[i].resize(n);
dis[i] = 1000000000;
}
for(int i = 0; i < n; i++){
for(int k = 0; k < n; k++) diff[i][k] = 0;
}
for(int i = 1; i < n; i++){
int parent = 0;
for(int k = 0; k < 10; k++){
if(decode_bit()) parent += (1 << k);
}
p[i] = parent;
adj[i].push_back(parent);
adj[parent].push_back(i);
}
dis[0] = j = 0;
vector<int>b = {0};
while(j < b.size()){
// cerr << j << endl;
for(auto s: adj[b[j]]){
if(dis[s] == 1000000000){
dis[s] = dis[b[j]] + 1;
b.push_back(s);
}
}
j++;
}
for(int i = 0; i < n; i++) {
if (dis[i] == 1000000000) assert(0);
hops(0,i, dis[i]);
}
for(int i = 1; i < h; i++){
for(int k = 1; k < n; k++){
if(!decode_bit()){
diff[k][p[k]] = diff[p[k]][k] = 0;
}else{
if(decode_bit()){
diff[k][p[k]] = 1;
diff[p[k]][k] = -1;
}else{
diff[p[k]][k] = 1;
diff[k][p[k]] = -1;
}
}
}
vector<int>pc(n, 1000000000);
pc[i] = j = 0;
vector<int>bb = {i};
while(j < bb.size()){
for(auto s:adj[bb[j]]){
if(pc[s] == 1000000000){
pc[s] = pc[bb[j]] + diff[bb[j]][s];
bb.push_back(s);
}
}
j++;
}
for(int t = 0; t < n; t++){
// if (pc[t] == 1000000000) cerr << t << endl;
hops(i,t,pc[t]);
}
}
}
Compilation message
encoder.cpp: In function 'void encode(int, int, int, int*, int*)':
encoder.cpp:27:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | while(j < d.size()){
| ~~^~~~~~~~~~
encoder.cpp:50:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | while(j < b.size()){
| ~~^~~~~~~~~~
decoder.cpp: In function 'void decode(int, int)':
decoder.cpp:33:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | while(j < b.size()){
| ~~^~~~~~~~~~
decoder.cpp:66:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | while(j < bb.size()){
| ~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
220 ms |
14016 KB |
Output is correct - 62913 call(s) of encode_bit() |
2 |
Correct |
3 ms |
4604 KB |
Output is correct - 52 call(s) of encode_bit() |
3 |
Correct |
26 ms |
8488 KB |
Output is correct - 58901 call(s) of encode_bit() |
4 |
Correct |
2 ms |
4648 KB |
Output is correct - 62 call(s) of encode_bit() |
5 |
Correct |
24 ms |
8600 KB |
Output is correct - 56288 call(s) of encode_bit() |
6 |
Correct |
26 ms |
9532 KB |
Output is correct - 60905 call(s) of encode_bit() |
7 |
Correct |
40 ms |
9624 KB |
Output is correct - 50828 call(s) of encode_bit() |
8 |
Correct |
26 ms |
9064 KB |
Output is partially correct - 76800 call(s) of encode_bit() |
9 |
Correct |
30 ms |
9452 KB |
Output is partially correct - 78646 call(s) of encode_bit() |
10 |
Correct |
27 ms |
9500 KB |
Output is partially correct - 78245 call(s) of encode_bit() |
11 |
Correct |
31 ms |
9576 KB |
Output is partially correct - 76543 call(s) of encode_bit() |
12 |
Correct |
31 ms |
9544 KB |
Output is partially correct - 79920 call(s) of encode_bit() |
13 |
Correct |
41 ms |
9944 KB |
Output is correct - 58326 call(s) of encode_bit() |
14 |
Correct |
27 ms |
9424 KB |
Output is partially correct - 77694 call(s) of encode_bit() |
15 |
Correct |
32 ms |
9400 KB |
Output is partially correct - 76176 call(s) of encode_bit() |
16 |
Correct |
47 ms |
9900 KB |
Output is partially correct - 72118 call(s) of encode_bit() |
17 |
Correct |
43 ms |
9892 KB |
Output is partially correct - 74009 call(s) of encode_bit() |
18 |
Correct |
50 ms |
10176 KB |
Output is correct - 69823 call(s) of encode_bit() |
19 |
Correct |
39 ms |
9628 KB |
Output is correct - 66843 call(s) of encode_bit() |
20 |
Correct |
64 ms |
10288 KB |
Output is correct - 63570 call(s) of encode_bit() |
21 |
Correct |
65 ms |
10436 KB |
Output is correct - 64320 call(s) of encode_bit() |
22 |
Correct |
56 ms |
9768 KB |
Output is correct - 53039 call(s) of encode_bit() |
23 |
Correct |
63 ms |
10680 KB |
Output is correct - 56825 call(s) of encode_bit() |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
220 ms |
14016 KB |
Output is correct - 62913 call(s) of encode_bit() |
2 |
Correct |
3 ms |
4604 KB |
Output is correct - 52 call(s) of encode_bit() |
3 |
Correct |
26 ms |
8488 KB |
Output is correct - 58901 call(s) of encode_bit() |
4 |
Correct |
2 ms |
4648 KB |
Output is correct - 62 call(s) of encode_bit() |
5 |
Correct |
24 ms |
8600 KB |
Output is correct - 56288 call(s) of encode_bit() |
6 |
Correct |
26 ms |
9532 KB |
Output is correct - 60905 call(s) of encode_bit() |
7 |
Correct |
40 ms |
9624 KB |
Output is correct - 50828 call(s) of encode_bit() |
8 |
Correct |
26 ms |
9064 KB |
Output is partially correct - 76800 call(s) of encode_bit() |
9 |
Correct |
30 ms |
9452 KB |
Output is partially correct - 78646 call(s) of encode_bit() |
10 |
Correct |
27 ms |
9500 KB |
Output is partially correct - 78245 call(s) of encode_bit() |
11 |
Correct |
31 ms |
9576 KB |
Output is partially correct - 76543 call(s) of encode_bit() |
12 |
Correct |
31 ms |
9544 KB |
Output is partially correct - 79920 call(s) of encode_bit() |
13 |
Correct |
41 ms |
9944 KB |
Output is correct - 58326 call(s) of encode_bit() |
14 |
Correct |
27 ms |
9424 KB |
Output is partially correct - 77694 call(s) of encode_bit() |
15 |
Correct |
32 ms |
9400 KB |
Output is partially correct - 76176 call(s) of encode_bit() |
16 |
Correct |
47 ms |
9900 KB |
Output is partially correct - 72118 call(s) of encode_bit() |
17 |
Correct |
43 ms |
9892 KB |
Output is partially correct - 74009 call(s) of encode_bit() |
18 |
Correct |
50 ms |
10176 KB |
Output is correct - 69823 call(s) of encode_bit() |
19 |
Correct |
39 ms |
9628 KB |
Output is correct - 66843 call(s) of encode_bit() |
20 |
Correct |
64 ms |
10288 KB |
Output is correct - 63570 call(s) of encode_bit() |
21 |
Correct |
65 ms |
10436 KB |
Output is correct - 64320 call(s) of encode_bit() |
22 |
Correct |
56 ms |
9768 KB |
Output is correct - 53039 call(s) of encode_bit() |
23 |
Correct |
63 ms |
10680 KB |
Output is correct - 56825 call(s) of encode_bit() |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
220 ms |
14016 KB |
Output is correct - 62913 call(s) of encode_bit() |
2 |
Correct |
3 ms |
4604 KB |
Output is correct - 52 call(s) of encode_bit() |
3 |
Correct |
26 ms |
8488 KB |
Output is correct - 58901 call(s) of encode_bit() |
4 |
Correct |
2 ms |
4648 KB |
Output is correct - 62 call(s) of encode_bit() |
5 |
Correct |
24 ms |
8600 KB |
Output is correct - 56288 call(s) of encode_bit() |
6 |
Correct |
26 ms |
9532 KB |
Output is correct - 60905 call(s) of encode_bit() |
7 |
Correct |
40 ms |
9624 KB |
Output is correct - 50828 call(s) of encode_bit() |
8 |
Correct |
26 ms |
9064 KB |
Output is partially correct - 76800 call(s) of encode_bit() |
9 |
Correct |
30 ms |
9452 KB |
Output is partially correct - 78646 call(s) of encode_bit() |
10 |
Correct |
27 ms |
9500 KB |
Output is partially correct - 78245 call(s) of encode_bit() |
11 |
Correct |
31 ms |
9576 KB |
Output is partially correct - 76543 call(s) of encode_bit() |
12 |
Correct |
31 ms |
9544 KB |
Output is partially correct - 79920 call(s) of encode_bit() |
13 |
Correct |
41 ms |
9944 KB |
Output is correct - 58326 call(s) of encode_bit() |
14 |
Correct |
27 ms |
9424 KB |
Output is partially correct - 77694 call(s) of encode_bit() |
15 |
Correct |
32 ms |
9400 KB |
Output is partially correct - 76176 call(s) of encode_bit() |
16 |
Correct |
47 ms |
9900 KB |
Output is partially correct - 72118 call(s) of encode_bit() |
17 |
Correct |
43 ms |
9892 KB |
Output is partially correct - 74009 call(s) of encode_bit() |
18 |
Correct |
50 ms |
10176 KB |
Output is correct - 69823 call(s) of encode_bit() |
19 |
Correct |
39 ms |
9628 KB |
Output is correct - 66843 call(s) of encode_bit() |
20 |
Correct |
64 ms |
10288 KB |
Output is correct - 63570 call(s) of encode_bit() |
21 |
Correct |
65 ms |
10436 KB |
Output is correct - 64320 call(s) of encode_bit() |
22 |
Correct |
56 ms |
9768 KB |
Output is correct - 53039 call(s) of encode_bit() |
23 |
Correct |
63 ms |
10680 KB |
Output is correct - 56825 call(s) of encode_bit() |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
220 ms |
14016 KB |
Output is correct - 62913 call(s) of encode_bit() |
2 |
Correct |
3 ms |
4604 KB |
Output is correct - 52 call(s) of encode_bit() |
3 |
Correct |
26 ms |
8488 KB |
Output is correct - 58901 call(s) of encode_bit() |
4 |
Correct |
2 ms |
4648 KB |
Output is correct - 62 call(s) of encode_bit() |
5 |
Correct |
24 ms |
8600 KB |
Output is correct - 56288 call(s) of encode_bit() |
6 |
Correct |
26 ms |
9532 KB |
Output is correct - 60905 call(s) of encode_bit() |
7 |
Correct |
40 ms |
9624 KB |
Output is correct - 50828 call(s) of encode_bit() |
8 |
Correct |
26 ms |
9064 KB |
Output is partially correct - 76800 call(s) of encode_bit() |
9 |
Correct |
30 ms |
9452 KB |
Output is partially correct - 78646 call(s) of encode_bit() |
10 |
Correct |
27 ms |
9500 KB |
Output is partially correct - 78245 call(s) of encode_bit() |
11 |
Correct |
31 ms |
9576 KB |
Output is partially correct - 76543 call(s) of encode_bit() |
12 |
Correct |
31 ms |
9544 KB |
Output is partially correct - 79920 call(s) of encode_bit() |
13 |
Correct |
41 ms |
9944 KB |
Output is correct - 58326 call(s) of encode_bit() |
14 |
Correct |
27 ms |
9424 KB |
Output is partially correct - 77694 call(s) of encode_bit() |
15 |
Correct |
32 ms |
9400 KB |
Output is partially correct - 76176 call(s) of encode_bit() |
16 |
Correct |
47 ms |
9900 KB |
Output is partially correct - 72118 call(s) of encode_bit() |
17 |
Correct |
43 ms |
9892 KB |
Output is partially correct - 74009 call(s) of encode_bit() |
18 |
Correct |
50 ms |
10176 KB |
Output is correct - 69823 call(s) of encode_bit() |
19 |
Correct |
39 ms |
9628 KB |
Output is correct - 66843 call(s) of encode_bit() |
20 |
Correct |
64 ms |
10288 KB |
Output is correct - 63570 call(s) of encode_bit() |
21 |
Correct |
65 ms |
10436 KB |
Output is correct - 64320 call(s) of encode_bit() |
22 |
Correct |
56 ms |
9768 KB |
Output is correct - 53039 call(s) of encode_bit() |
23 |
Correct |
63 ms |
10680 KB |
Output is correct - 56825 call(s) of encode_bit() |