Submission #574373

# Submission time Handle Problem Language Result Execution time Memory
574373 2022-06-08T12:43:30 Z SlavicG Saveit (IOI10_saveit) C++17
0 / 100
1513 ms 72608 KB
#include "bits/stdc++.h"
#include "grader.h"
using namespace std;
 
#define ll long long
 
#define       forn(i,n)              for(int i=0;i<n;i++)
#define          all(v)              v.begin(), v.end()
#define         rall(v)              v.rbegin(),v.rend()
 
#define            pb                push_back
#define          sz(a)               (int)a.size()
 
vector<int> bfs(int start, vector<vector<int>>& adj) {
    int n = sz(adj);
    vector<int> dist(n, -1);
    dist[start] = 0;
    queue<int> q;
    q.push(start);
    while(!q.empty()) {
        int u = q.front();
        q.pop();
        for(int v: adj[u]) {
            if(dist[v] == -1) {
                dist[v] = dist[u] + 1;
                q.push(v);
            }
        }
    }
    return dist;
}
void dfs(int u, vector<bool>& vis, vector<vector<int>>& adj, vector<int>& par) {
    vis[u] = true;
    for(int v: adj[u]) {
        if(!vis[v]) {
            par[v] = u;
            dfs(v, vis, adj, par);
        }
    }
}

map<vector<int>, int> mp;
int amogus = 0;
void rec(vector<int> v) {
    if(sz(v) == 3) {
        if(mp.count(v)) return;
        mp[v] = amogus++;
    } else {
        for(int i = 0; i <= 2; ++i) {
            v.pb(i);
            rec(v);
            v.pop_back();
        }
    }
}
void encode(int n, int h, int m, int *v1, int *v2){
    vector<vector<int>> adj(n);
    for(int i = 0; i < m; ++i) {
        adj[v1[i]].pb(v2[i]);
        adj[v2[i]].pb(v1[i]);
    }
    vector<vector<int>> dist(n);
    forn(i, n) dist[i] = bfs(i, adj);
    for(int i = 0;i < h; ++i) {
        for(int j = 0; j < 10; ++j) {
            if(dist[0][i] & (1 << j)) encode_bit(1);
            else encode_bit(0);
        }
    }
    vector<bool> vis(n, false);
    vector<int> parent(n);
    iota(all(parent), 0);

    dfs(0, vis, adj, parent);

    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < 10; ++j) {
            if(parent[i] & (1 << j)) encode_bit(1);
            else encode_bit(0);
        }
    }
    //dist[node][i] = dist[parent[node]][i] (0)
    //dist[node][i] = dist[parent[node]][i] - 1 (1)
    //dist[node][i] = dist[parent[node]][i] + 1 (2)

    rec({});
    for(int j = 0; j < h; ++j) {
        vector<int> v;
        for(int i = 0; i < n; ++i) {
            if(dist[i][j] == dist[parent[i]][j]) v.pb(0);
            else if(dist[i][j] == dist[parent[i]][j] - 1) v.pb(1);
            else {
                assert(dist[i][j] == dist[parent[i]][j] + 1);
                v.pb(2);
            }
        }
        for(int i = 0; i + 2 < n; i += 3) {
            for(int f = 0; f < 5; ++j) {
                if(mp[{v[i], v[i + 1], v[i + 2]}] & (1 << f)) {
                    encode_bit(1);
                } else encode_bit(0);
            }
        }
        if(n % 3 == 1) {
            for(int f = 0; f < 2; ++f) {
                if(v.back() & (1 << f)) encode_bit(1);
                else encode_bit(0);
            }
        } else if(n % 3 == 2) {
            for(int k = sz(v) - 2; k < sz(v); ++k) {
                for(int f = 0; f < 2; ++f) {
                    if(v[k] & (1 << f)) encode_bit(1);
                    else encode_bit(0);
                }
            }
        }
    }
}

/*
void solve() {  

} 
     
int32_t main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
} 
 
*/
#include "bits/stdc++.h"
#include "grader.h"
#include "decoder.h"

using namespace std;
#define ll long long
 
#define       forn(i,n)              for(int i=0;i<n;i++)
#define          all(v)              v.begin(), v.end()
#define         rall(v)              v.rbegin(),v.rend()
 
#define            pb                push_back
#define          sz(a)               (int)a.size()

const int N = 1000;
int dist[N][40], type[N][40];

vector<int> adj[N];

map<vector<int>, int> mp;
int amogus = 0;
map<int, vector<int>> Paiu;

void rec(vector<int> v) {
    if(sz(v) == 3) {
        if(mp.count(v)) return;
        mp[v] = amogus;
        Paiu[amogus] = v;
        ++amogus;
    } else {
        for(int i = 0; i <= 2; ++i) {
            v.pb(i);
            rec(v);
            v.pop_back();
        }
    }
}

void dfs(int u, int par, int h) {
    for(int v: adj[u]) {
        if(v == par) continue;
        for(int j = 0; j < h; ++j) {
            if(type[v][j] == 0) dist[v][j] = dist[u][j];
            else if(type[v][j] == 1) dist[v][j] = dist[u][j] - 1;
            else dist[v][j] = dist[u][j] + 1;
        }
        dfs(v, u, h);
    }
}
void decode(int n, int h) {
    for(int i = 0; i < h; ++i) {
        for(int j = 0; j < 10; ++j) {
            if(decode_bit()) dist[0][i] += (1 << j);
        }
    }
    for(int i = 0;i < n; ++i) {
        int node = 0;
        for(int j = 0; j < 10; ++j) {
            if(decode_bit()) node += (1 << j);
        }
        if(node != i) adj[node].pb(i);
    }

    rec({});
    for(int j = 0; j < h; ++j) {
        for(int i = 0; i + 2 < n; i += 3) {
            int number = 0;
            for(int f = 0; f < 5; ++f) {
                if(decode_bit()) number += (1 << f);
            }
            vector<int> f = Paiu[number];
            type[i][j] = f[0], type[i + 1][j] = f[1], type[i + 2][j] = f[2];
        }
        if(n % 3 == 1) {
            for(int f = 0; f < 2; ++f) {
                if(decode_bit()) type[n - 1][j] += (1 << f);
            }
        } else if(n % 3 == 2) {
            for(int k = n - 2; k < n; ++k) {
                for(int f = 0; f < 2; ++f) {
                    if(decode_bit()) type[k][j] += (1 << f);
                }
            }
        }
    }
    dfs(0, -1, h);
    for(int i = 0; i < h; ++i) {
        for(int j = 0; j < n; ++j) {
            dist[i][j] = dist[j][i];
        }
    }
    for(int i = 0; i < h; ++i) {
        for(int j = 0; j < n; ++j) {
            hops(i, j, dist[i][j]);
        }
    }
}
/*
void solve() {  
    
}   
     
int32_t main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
}
*/
# Verdict Execution time Memory Grader output
1 Incorrect 1513 ms 72608 KB too many calls to encode_bit(b) function
2 Incorrect 913 ms 63256 KB too many calls to encode_bit(b) function
3 Incorrect 879 ms 66672 KB too many calls to encode_bit(b) function
4 Incorrect 877 ms 63208 KB too many calls to encode_bit(b) function
5 Incorrect 932 ms 66916 KB too many calls to encode_bit(b) function
6 Incorrect 831 ms 67556 KB too many calls to encode_bit(b) function
7 Incorrect 990 ms 68100 KB too many calls to encode_bit(b) function
8 Incorrect 890 ms 67084 KB too many calls to encode_bit(b) function
9 Incorrect 879 ms 67388 KB too many calls to encode_bit(b) function
10 Incorrect 846 ms 67448 KB too many calls to encode_bit(b) function
11 Incorrect 897 ms 67748 KB too many calls to encode_bit(b) function
12 Incorrect 852 ms 67456 KB too many calls to encode_bit(b) function
13 Incorrect 808 ms 68256 KB too many calls to encode_bit(b) function
14 Incorrect 809 ms 67332 KB too many calls to encode_bit(b) function
15 Incorrect 890 ms 67584 KB too many calls to encode_bit(b) function
16 Incorrect 859 ms 68008 KB too many calls to encode_bit(b) function
17 Incorrect 824 ms 67800 KB too many calls to encode_bit(b) function
18 Incorrect 907 ms 68312 KB too many calls to encode_bit(b) function
19 Incorrect 923 ms 67884 KB too many calls to encode_bit(b) function
20 Incorrect 1051 ms 68456 KB too many calls to encode_bit(b) function
21 Incorrect 1041 ms 68504 KB too many calls to encode_bit(b) function
22 Incorrect 957 ms 68000 KB too many calls to encode_bit(b) function
23 Incorrect 936 ms 68920 KB too many calls to encode_bit(b) function
# Verdict Execution time Memory Grader output
1 Incorrect 1513 ms 72608 KB too many calls to encode_bit(b) function
2 Incorrect 913 ms 63256 KB too many calls to encode_bit(b) function
3 Incorrect 879 ms 66672 KB too many calls to encode_bit(b) function
4 Incorrect 877 ms 63208 KB too many calls to encode_bit(b) function
5 Incorrect 932 ms 66916 KB too many calls to encode_bit(b) function
6 Incorrect 831 ms 67556 KB too many calls to encode_bit(b) function
7 Incorrect 990 ms 68100 KB too many calls to encode_bit(b) function
8 Incorrect 890 ms 67084 KB too many calls to encode_bit(b) function
9 Incorrect 879 ms 67388 KB too many calls to encode_bit(b) function
10 Incorrect 846 ms 67448 KB too many calls to encode_bit(b) function
11 Incorrect 897 ms 67748 KB too many calls to encode_bit(b) function
12 Incorrect 852 ms 67456 KB too many calls to encode_bit(b) function
13 Incorrect 808 ms 68256 KB too many calls to encode_bit(b) function
14 Incorrect 809 ms 67332 KB too many calls to encode_bit(b) function
15 Incorrect 890 ms 67584 KB too many calls to encode_bit(b) function
16 Incorrect 859 ms 68008 KB too many calls to encode_bit(b) function
17 Incorrect 824 ms 67800 KB too many calls to encode_bit(b) function
18 Incorrect 907 ms 68312 KB too many calls to encode_bit(b) function
19 Incorrect 923 ms 67884 KB too many calls to encode_bit(b) function
20 Incorrect 1051 ms 68456 KB too many calls to encode_bit(b) function
21 Incorrect 1041 ms 68504 KB too many calls to encode_bit(b) function
22 Incorrect 957 ms 68000 KB too many calls to encode_bit(b) function
23 Incorrect 936 ms 68920 KB too many calls to encode_bit(b) function
# Verdict Execution time Memory Grader output
1 Incorrect 1513 ms 72608 KB too many calls to encode_bit(b) function
2 Incorrect 913 ms 63256 KB too many calls to encode_bit(b) function
3 Incorrect 879 ms 66672 KB too many calls to encode_bit(b) function
4 Incorrect 877 ms 63208 KB too many calls to encode_bit(b) function
5 Incorrect 932 ms 66916 KB too many calls to encode_bit(b) function
6 Incorrect 831 ms 67556 KB too many calls to encode_bit(b) function
7 Incorrect 990 ms 68100 KB too many calls to encode_bit(b) function
8 Incorrect 890 ms 67084 KB too many calls to encode_bit(b) function
9 Incorrect 879 ms 67388 KB too many calls to encode_bit(b) function
10 Incorrect 846 ms 67448 KB too many calls to encode_bit(b) function
11 Incorrect 897 ms 67748 KB too many calls to encode_bit(b) function
12 Incorrect 852 ms 67456 KB too many calls to encode_bit(b) function
13 Incorrect 808 ms 68256 KB too many calls to encode_bit(b) function
14 Incorrect 809 ms 67332 KB too many calls to encode_bit(b) function
15 Incorrect 890 ms 67584 KB too many calls to encode_bit(b) function
16 Incorrect 859 ms 68008 KB too many calls to encode_bit(b) function
17 Incorrect 824 ms 67800 KB too many calls to encode_bit(b) function
18 Incorrect 907 ms 68312 KB too many calls to encode_bit(b) function
19 Incorrect 923 ms 67884 KB too many calls to encode_bit(b) function
20 Incorrect 1051 ms 68456 KB too many calls to encode_bit(b) function
21 Incorrect 1041 ms 68504 KB too many calls to encode_bit(b) function
22 Incorrect 957 ms 68000 KB too many calls to encode_bit(b) function
23 Incorrect 936 ms 68920 KB too many calls to encode_bit(b) function
# Verdict Execution time Memory Grader output
1 Incorrect 1513 ms 72608 KB too many calls to encode_bit(b) function
2 Incorrect 913 ms 63256 KB too many calls to encode_bit(b) function
3 Incorrect 879 ms 66672 KB too many calls to encode_bit(b) function
4 Incorrect 877 ms 63208 KB too many calls to encode_bit(b) function
5 Incorrect 932 ms 66916 KB too many calls to encode_bit(b) function
6 Incorrect 831 ms 67556 KB too many calls to encode_bit(b) function
7 Incorrect 990 ms 68100 KB too many calls to encode_bit(b) function
8 Incorrect 890 ms 67084 KB too many calls to encode_bit(b) function
9 Incorrect 879 ms 67388 KB too many calls to encode_bit(b) function
10 Incorrect 846 ms 67448 KB too many calls to encode_bit(b) function
11 Incorrect 897 ms 67748 KB too many calls to encode_bit(b) function
12 Incorrect 852 ms 67456 KB too many calls to encode_bit(b) function
13 Incorrect 808 ms 68256 KB too many calls to encode_bit(b) function
14 Incorrect 809 ms 67332 KB too many calls to encode_bit(b) function
15 Incorrect 890 ms 67584 KB too many calls to encode_bit(b) function
16 Incorrect 859 ms 68008 KB too many calls to encode_bit(b) function
17 Incorrect 824 ms 67800 KB too many calls to encode_bit(b) function
18 Incorrect 907 ms 68312 KB too many calls to encode_bit(b) function
19 Incorrect 923 ms 67884 KB too many calls to encode_bit(b) function
20 Incorrect 1051 ms 68456 KB too many calls to encode_bit(b) function
21 Incorrect 1041 ms 68504 KB too many calls to encode_bit(b) function
22 Incorrect 957 ms 68000 KB too many calls to encode_bit(b) function
23 Incorrect 936 ms 68920 KB too many calls to encode_bit(b) function