# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
829535 |
2023-08-18T12:14:05 Z |
Antekb |
Saveit (IOI10_saveit) |
C++17 |
|
5502 ms |
13832 KB |
#include "grader.h"
#include "encoder.h"
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define pp pop_back;
using namespace std;
using vi = vector<int>;
using pii = pair<int, int>;
void nadaj(vi &V, int x, int b){
for(int i=0; i<b; i++){
V.pb(!!(x&(1<<i)));
}
}
void encode2(vi &ans, int n, int h, int m, int *v1, int *v2){
vi E[n];
int czy[n][h], dist[n][h];
for(int i=0; i<n; i++){
for(int j=0; j<h; j++){
czy[i][j]=(i==j);
dist[i][j]=1e9*(i!=j);
}
}
vi edg;
for(int i=0; i<m; i++){
E[v1[i]].pb(edg.size());
edg.pb(v2[i]);
E[v2[i]].pb(edg.size());
edg.pb(v1[i]);
}
for(int s=0; s<h; s++){
vi V;
V.pb(s);
for(int i=0; i<V.size(); i++){
int v=V[i];
for(int e:E[v]){
if(dist[edg[e]][s]==1e9){
dist[edg[e]][s]=dist[v][s]+1;
V.pb(edg[e]);
}
}
}
}
vi E2[n];
for(int v=0; v<n; v++){
int ile=0;
for(int u=0; u<n; u++){
if(u==v)continue;
bool b=1;
for(int i=0; i<h; i++){
if(dist[u][i]+1<dist[v][i] || dist[v][i]+1<dist[u][i]){
b=0;
}
}
if(!b)continue;
b=0;
for(int i=0; i<h; i++){
if(!czy[u][i] && dist[u][i]==dist[v][i]+1){
b=1;
}
if(!czy[v][i] && dist[v][i]==dist[u][i]+1){
b=1;
}
}
if(b)ile++;
}
if(ile>=100){
for(int u=0; u<n; u++){
if(u==v)continue;
bool b=1;
for(int i=0; i<h; i++){
if(dist[u][i]+1<dist[v][i] || dist[v][i]+1<dist[u][i]){
b=0;
}
}
if(!b)continue;
for(int i=0; i<h; i++){
if(!czy[u][i] && dist[u][i]==dist[v][i]+1){
czy[u][i]=1;
E2[v].pb(u);
}
if(!czy[v][i] && dist[v][i]==dist[u][i]+1){
czy[v][i]=1;
E2[v].pb(u);
}
}
}
}
}
int sum=0;
for(int t=h; t>0; t--){
for(int u=0; u<n; u++){
for(int v=0; v<u; v++){
bool b=1;
for(int i=0; i<h; i++){
if(dist[u][i]+1<dist[v][i] || dist[v][i]+1<dist[u][i]){
b=0;
}
}
if(!b)continue;
int ile=0;
for(int i=0; i<h; i++){
if(!czy[u][i] && dist[u][i]==dist[v][i]+1){
ile++;
}
if(!czy[v][i] && dist[v][i]==dist[u][i]+1){
ile++;
}
}
if(ile==t){
//cerr<<t<<"\n";
sum+=t;
if(2*(u-v)<n)E2[v].pb(u-v);
else E2[u].pb(v-u+n);
for(int i=0; i<h; i++){
if(!czy[u][i] && dist[u][i]==dist[v][i]+1){
czy[u][i]=1;
}
if(!czy[v][i] && dist[v][i]==dist[u][i]+1){
czy[v][i]=1;
}
}
}
}
}
}
cerr<<sum<<"\n";
for(int i=0; i<n; i++){
sort(E2[i].begin(), E2[i].end());
nadaj(ans, min((int)E2[i].size(), 100), 7);
if(E2[i].size()>=100){
vi V(n);
for(int u:E2[i]){
V[u]=1;
}
for(int j:V){
nadaj(ans, j, 1);
}
}
else{
for(int u:E2[i]){
nadaj(ans, u, 9);
}
}
}
return;
}
void encode3(vi &ans, int n, int h, int m, int *v1, int *v2){
vi E[n];
int czy[n][h], dist[n][h];
for(int i=0; i<n; i++){
for(int j=0; j<h; j++){
czy[i][j]=(i==j);
dist[i][j]=1e9*(i!=j);
}
}
vi edg;
for(int i=0; i<m; i++){
E[v1[i]].pb(edg.size());
edg.pb(v2[i]);
E[v2[i]].pb(edg.size());
edg.pb(v1[i]);
}
for(int s=0; s<h; s++){
vi V;
V.pb(s);
for(int i=0; i<V.size(); i++){
int v=V[i];
for(int e:E[v]){
if(dist[edg[e]][s]==1e9){
dist[edg[e]][s]=dist[v][s]+1;
V.pb(edg[e]);
}
}
}
}
vi E2[n];
int sum=0;
for(int t=h; t>0; t--){
for(int u=0; u<n; u++){
for(int v=0; v<u; v++){
bool b=1;
for(int i=0; i<h; i++){
if(dist[u][i]+1<dist[v][i] || dist[v][i]+1<dist[u][i]){
b=0;
}
}
if(!b)continue;
int ile=0;
for(int i=0; i<h; i++){
if(!czy[u][i] && dist[u][i]==dist[v][i]+1){
ile++;
}
if(!czy[v][i] && dist[v][i]==dist[u][i]+1){
ile++;
}
}
if(ile==t){
//cerr<<t<<"\n";
sum+=t;
if(2*(u-v)<n)E2[v].pb(u-v);
else E2[u].pb(v-u+n);
for(int i=0; i<h; i++){
if(!czy[u][i] && dist[u][i]==dist[v][i]+1){
czy[u][i]=1;
}
if(!czy[v][i] && dist[v][i]==dist[u][i]+1){
czy[v][i]=1;
}
}
}
}
}
}
cerr<<sum<<"\n";
for(int i=0; i<n; i++){
sort(E2[i].begin(), E2[i].end());
nadaj(ans, min((int)E2[i].size(), 100), 7);
if(E2[i].size()>=100){
vi V(n);
for(int u:E2[i]){
V[u]=1;
}
for(int j:V){
nadaj(ans, j, 1);
}
}
else{
for(int u:E2[i]){
nadaj(ans, u, 9);
}
}
}
return;
}
void encode(int n, int h, int m, int *v1, int *v2){
vi V, V2;
encode2(V, n, h, m, v1, v2);
encode3(V2, n, h, m, v1, v2);
if(V2.size()<V.size())V=V2;
for(int i:V){
encode_bit(i);
}
}
#include "grader.h"
#include "decoder.h"
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define pp pop_back;
using namespace std;
using vi = vector<int>;
using pii = pair<int, int>;
int czytaj(int b){
int x=0;
for(int i=0; i<b; i++){
x+=(int(decode_bit())<<i);
}
return x;
}
void decode(int n, int h) {
vi E[n];
for(int i=0;i<n; i++){
int k=czytaj(7);
//cerr<<k<<"\n";
if(k==100){
for(int j=0; j<n; j++){
if(czytaj(1)){
E[i].pb(j);
E[j].pb(i);
}
}
}
else{
while(k--){
int j=czytaj(9);
E[i].pb((i+j)%n);
E[j].pb((i+j)%n);
}
}
}
for(int s=0; s<h; s++){
vi V;
V.pb(s);
vi dist(n, 1e9);
dist[s]=0;
for(int i=0; i<V.size(); i++){
int v=V[i];
for(int u:E[v]){
if(dist[u]==1e9){
dist[u]=dist[v]+1;
V.pb(u);
}
}
}
for(int i=0; i<n; i++){
hops(s, i, dist[i]);
}
}
}
Compilation message
encoder.cpp: In function 'void encode2(vi&, int, int, int, int*, int*)':
encoder.cpp:35:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for(int i=0; i<V.size(); i++){
| ~^~~~~~~~~
encoder.cpp: In function 'void encode3(vi&, int, int, int, int*, int*)':
encoder.cpp:168:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
168 | for(int i=0; i<V.size(); i++){
| ~^~~~~~~~~
decoder.cpp: In function 'void decode(int, int)':
decoder.cpp:44:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for(int i=0; i<V.size(); i++){
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5502 ms |
13832 KB |
Output is correct - 43000 call(s) of encode_bit() |
2 |
Incorrect |
1 ms |
4604 KB |
wrong parameter |
3 |
Incorrect |
1603 ms |
5908 KB |
wrong parameter |
4 |
Incorrect |
3 ms |
4720 KB |
Output isn't correct |
5 |
Incorrect |
2361 ms |
6808 KB |
wrong parameter |
6 |
Incorrect |
2809 ms |
7024 KB |
wrong parameter |
7 |
Incorrect |
3518 ms |
7632 KB |
Output isn't correct |
8 |
Incorrect |
2962 ms |
5508 KB |
wrong parameter |
9 |
Incorrect |
1521 ms |
5596 KB |
wrong parameter |
10 |
Incorrect |
1519 ms |
5636 KB |
wrong parameter |
11 |
Incorrect |
1623 ms |
6180 KB |
wrong parameter |
12 |
Incorrect |
1849 ms |
5408 KB |
wrong parameter |
13 |
Incorrect |
2891 ms |
7384 KB |
wrong parameter |
14 |
Incorrect |
1908 ms |
5648 KB |
wrong parameter |
15 |
Incorrect |
1896 ms |
5668 KB |
wrong parameter |
16 |
Incorrect |
2245 ms |
7040 KB |
wrong parameter |
17 |
Incorrect |
2284 ms |
6824 KB |
wrong parameter |
18 |
Incorrect |
2836 ms |
7328 KB |
wrong parameter |
19 |
Incorrect |
2534 ms |
6620 KB |
wrong parameter |
20 |
Incorrect |
2776 ms |
7752 KB |
wrong parameter |
21 |
Incorrect |
3157 ms |
8356 KB |
wrong parameter |
22 |
Incorrect |
3365 ms |
7920 KB |
wrong parameter |
23 |
Incorrect |
3280 ms |
9156 KB |
wrong parameter |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5502 ms |
13832 KB |
Output is correct - 43000 call(s) of encode_bit() |
2 |
Incorrect |
1 ms |
4604 KB |
wrong parameter |
3 |
Incorrect |
1603 ms |
5908 KB |
wrong parameter |
4 |
Incorrect |
3 ms |
4720 KB |
Output isn't correct |
5 |
Incorrect |
2361 ms |
6808 KB |
wrong parameter |
6 |
Incorrect |
2809 ms |
7024 KB |
wrong parameter |
7 |
Incorrect |
3518 ms |
7632 KB |
Output isn't correct |
8 |
Incorrect |
2962 ms |
5508 KB |
wrong parameter |
9 |
Incorrect |
1521 ms |
5596 KB |
wrong parameter |
10 |
Incorrect |
1519 ms |
5636 KB |
wrong parameter |
11 |
Incorrect |
1623 ms |
6180 KB |
wrong parameter |
12 |
Incorrect |
1849 ms |
5408 KB |
wrong parameter |
13 |
Incorrect |
2891 ms |
7384 KB |
wrong parameter |
14 |
Incorrect |
1908 ms |
5648 KB |
wrong parameter |
15 |
Incorrect |
1896 ms |
5668 KB |
wrong parameter |
16 |
Incorrect |
2245 ms |
7040 KB |
wrong parameter |
17 |
Incorrect |
2284 ms |
6824 KB |
wrong parameter |
18 |
Incorrect |
2836 ms |
7328 KB |
wrong parameter |
19 |
Incorrect |
2534 ms |
6620 KB |
wrong parameter |
20 |
Incorrect |
2776 ms |
7752 KB |
wrong parameter |
21 |
Incorrect |
3157 ms |
8356 KB |
wrong parameter |
22 |
Incorrect |
3365 ms |
7920 KB |
wrong parameter |
23 |
Incorrect |
3280 ms |
9156 KB |
wrong parameter |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5502 ms |
13832 KB |
Output is correct - 43000 call(s) of encode_bit() |
2 |
Incorrect |
1 ms |
4604 KB |
wrong parameter |
3 |
Incorrect |
1603 ms |
5908 KB |
wrong parameter |
4 |
Incorrect |
3 ms |
4720 KB |
Output isn't correct |
5 |
Incorrect |
2361 ms |
6808 KB |
wrong parameter |
6 |
Incorrect |
2809 ms |
7024 KB |
wrong parameter |
7 |
Incorrect |
3518 ms |
7632 KB |
Output isn't correct |
8 |
Incorrect |
2962 ms |
5508 KB |
wrong parameter |
9 |
Incorrect |
1521 ms |
5596 KB |
wrong parameter |
10 |
Incorrect |
1519 ms |
5636 KB |
wrong parameter |
11 |
Incorrect |
1623 ms |
6180 KB |
wrong parameter |
12 |
Incorrect |
1849 ms |
5408 KB |
wrong parameter |
13 |
Incorrect |
2891 ms |
7384 KB |
wrong parameter |
14 |
Incorrect |
1908 ms |
5648 KB |
wrong parameter |
15 |
Incorrect |
1896 ms |
5668 KB |
wrong parameter |
16 |
Incorrect |
2245 ms |
7040 KB |
wrong parameter |
17 |
Incorrect |
2284 ms |
6824 KB |
wrong parameter |
18 |
Incorrect |
2836 ms |
7328 KB |
wrong parameter |
19 |
Incorrect |
2534 ms |
6620 KB |
wrong parameter |
20 |
Incorrect |
2776 ms |
7752 KB |
wrong parameter |
21 |
Incorrect |
3157 ms |
8356 KB |
wrong parameter |
22 |
Incorrect |
3365 ms |
7920 KB |
wrong parameter |
23 |
Incorrect |
3280 ms |
9156 KB |
wrong parameter |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5502 ms |
13832 KB |
Output is correct - 43000 call(s) of encode_bit() |
2 |
Incorrect |
1 ms |
4604 KB |
wrong parameter |
3 |
Incorrect |
1603 ms |
5908 KB |
wrong parameter |
4 |
Incorrect |
3 ms |
4720 KB |
Output isn't correct |
5 |
Incorrect |
2361 ms |
6808 KB |
wrong parameter |
6 |
Incorrect |
2809 ms |
7024 KB |
wrong parameter |
7 |
Incorrect |
3518 ms |
7632 KB |
Output isn't correct |
8 |
Incorrect |
2962 ms |
5508 KB |
wrong parameter |
9 |
Incorrect |
1521 ms |
5596 KB |
wrong parameter |
10 |
Incorrect |
1519 ms |
5636 KB |
wrong parameter |
11 |
Incorrect |
1623 ms |
6180 KB |
wrong parameter |
12 |
Incorrect |
1849 ms |
5408 KB |
wrong parameter |
13 |
Incorrect |
2891 ms |
7384 KB |
wrong parameter |
14 |
Incorrect |
1908 ms |
5648 KB |
wrong parameter |
15 |
Incorrect |
1896 ms |
5668 KB |
wrong parameter |
16 |
Incorrect |
2245 ms |
7040 KB |
wrong parameter |
17 |
Incorrect |
2284 ms |
6824 KB |
wrong parameter |
18 |
Incorrect |
2836 ms |
7328 KB |
wrong parameter |
19 |
Incorrect |
2534 ms |
6620 KB |
wrong parameter |
20 |
Incorrect |
2776 ms |
7752 KB |
wrong parameter |
21 |
Incorrect |
3157 ms |
8356 KB |
wrong parameter |
22 |
Incorrect |
3365 ms |
7920 KB |
wrong parameter |
23 |
Incorrect |
3280 ms |
9156 KB |
wrong parameter |