Submission #1065434

# Submission time Handle Problem Language Result Execution time Memory
1065434 2024-08-19T07:33:55 Z Jarif_Rahman Amusement Park (JOI17_amusement_park) C++17
0 / 100
2262 ms 262144 KB
#include "Joi.h"
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;

namespace {
    const int N = 10000;
    int n, m;
    vector<int> graph[N];
    int dis[N][N];

    void bfs(int source){
        queue<int> Q;
        fill(dis[source], dis[source]+n, -1);
        dis[source][source] = 0;
        Q.push(source);
        while(!Q.empty()){
            int nd = Q.front();
            Q.pop();
            for(int x: graph[nd]) if(dis[source][x] == -1){
                dis[source][x] = dis[source][nd]+1;
                Q.push(x);
            }
        }
    }
}

void Joi(int _n, int _m, int A[], int B[], ll X, int T){
    n = _n, m = _m;
    for(int i = 0; i < m; i++){
        graph[A[i]].push_back(B[i]);
        graph[B[i]].push_back(A[i]);
    }

    vector<int> bin;
    for(int i = 0; i < 60; i++){
        bin.push_back(X%2);
        X/=2;
    }

    for(int i = 0; i < n; i++) bfs(i);
    vector<int> msg(n, -1);

    for(int i = 0; i < n; i++){
        vector<int> md(60, 1e8);
        for(int j = 0; j < n; j++) if(msg[j] != -1) md[msg[j]] = min(md[msg[j]], dis[i][j]);
        int x = 0, d = md[0];
        for(int j = 1; j < 60; j++) if(md[j] > d) d = md[j], x = j;
        msg[i] = x;
    }

    for(int i = 0; i < n; i++) MessageBoard(i, bin[msg[i]]);
}
#include "Ioi.h"
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;

namespace {
    const int N = 10000;
    int n, m;
    vector<int> graph[N];
    int dis[N][N];
    vector<int> tree[N];

    void bfs(int source){
        queue<int> Q;
        fill(dis[source], dis[source]+n, -1);
        dis[source][source] = 0;
        Q.push(source);
        while(!Q.empty()){
            int nd = Q.front();
            Q.pop();
            for(int x: graph[nd]) if(dis[source][x] == -1){
                dis[source][x] = dis[source][nd]+1;
                Q.push(x);
            }
        }
    }
}

ll Ioi(int _n, int _m, int A[], int B[], int p, int v, int T){
    n = _n, m = _m;
    for(int i = 0; i < m; i++){
        graph[A[i]].push_back(B[i]);
        graph[B[i]].push_back(A[i]);
    }

    for(int i = 0; i < n; i++) bfs(i);
    vector<int> msg(n, -1);
    for(int i = 0; i < n; i++){
        vector<int> md(60, 1e8);
        for(int j = 0; j < n; j++) if(msg[j] != -1) md[msg[j]] = min(md[msg[j]], dis[i][j]);
        int x = 0, d = md[0];
        for(int j = 1; j < 60; j++) if(md[j] > d) d = md[j], x = j;
        msg[i] = x;
    }

    vector<bool> done(60, 0);
    int left = 60;
    vector<bool> bl(n, 0);

    done[msg[p]] = 1;
    left--;
    bl[p] = 1;

    vector<pair<int, int>> nxt;
    for(int x: graph[p]) if(!bl[x]){
        bl[x] = 1;
        nxt.push_back({x, p});
    }

    while(left){
        int nd = -1, ss = -1;
        for(int i = int(nxt.size())-1; i >= 0; i--) if(!done[msg[nxt[i].first]]){
            tie(nd, ss) = nxt[i];
            nxt.erase(nxt.begin()+i);
            break;
        }
        if(nd == -1){
            tie(nd, ss) = nxt.back();
            nxt.pop_back();
        }

        if(!done[msg[nd]]) left--;
        done[msg[nd]] = 1;
        bl[nd] = 1;

        tree[ss].push_back(nd);

        for(int x: graph[nd]) if(!bl[x]){
            bl[x] = 1;
            nxt.push_back({x, nd});
        }
    }

    vector<int> bin(60);
    bin[p] = v;

    function<void(int)> dfs = [&](int nd){
        for(int x: tree[nd]){
            bin[msg[x]] = Move(x);
            dfs(x);
            Move(nd);
        }
    };
    dfs(p);

    ll X = 0;
    for(int i = 0; i < 60; i++) if(bin[i]) X+=(1LL<<i);
    return X;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 11548 KB Output is correct
2 Correct 2 ms 15644 KB Output is correct
3 Correct 5 ms 27936 KB Output is correct
4 Runtime error 12 ms 22280 KB Execution killed with signal 6
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2167 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 11532 KB Output is correct
2 Correct 2 ms 11540 KB Output is correct
3 Correct 2 ms 11536 KB Output is correct
4 Correct 57 ms 72660 KB Output is correct
5 Runtime error 88 ms 121804 KB Execution killed with signal 6
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2148 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2262 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -