답안 #1065490

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1065490 2024-08-19T08:24:06 Z Jarif_Rahman Amusement Park (JOI17_amusement_park) C++17
18 / 100
3000 ms 3136 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;
    const int k = 60;
    int n, m;
    vector<int> graph[N];
    int dis[N];

    void bfs(int source){
        queue<int> Q;
        fill(dis, dis+n, -1);
        dis[source] = 0;
        Q.push(source);
        while(!Q.empty()){
            int nd = Q.front();
            Q.pop();
            for(int x: graph[nd]) if(dis[x] == -1){
                dis[x] = dis[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 < k; i++){
        bin.push_back(X%2);
        X/=2;
    }

    vector<int> msg(n, -1);

    for(int i = 0; i < n; i++){
        bfs(i);
        vector<int> md(k, 1e8);
        for(int j = 0; j < n; j++) if(msg[j] != -1) md[msg[j]] = min(md[msg[j]], dis[j]);
        int x = 0, d = md[0];
        for(int j = 1; j < k; 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;
    const int k = 60;
    int n, m;
    vector<int> graph[N];
    int dis[N];
    vector<int> tree[N];

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

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

    vector<bool> done(k, 0);
    int left = k;
    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){
            assert(!nxt.empty());
            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(k);
    bin[msg[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 < k; i++) if(bin[i]) X+=(1LL<<i);
    return X;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1552 KB Output is correct
2 Correct 2 ms 1552 KB Output is correct
3 Correct 2 ms 1560 KB Output is correct
4 Correct 1 ms 1564 KB Output is correct
5 Correct 1 ms 1564 KB Output is correct
6 Correct 2 ms 1552 KB Output is correct
7 Correct 2 ms 1560 KB Output is correct
8 Correct 2 ms 1568 KB Output is correct
9 Correct 2 ms 1568 KB Output is correct
10 Correct 2 ms 1552 KB Output is correct
11 Correct 5 ms 1812 KB Output is correct
12 Correct 0 ms 1560 KB Output is correct
13 Correct 2 ms 1568 KB Output is correct
14 Correct 2 ms 1568 KB Output is correct
15 Correct 2 ms 1568 KB Output is correct
16 Correct 2 ms 1808 KB Output is correct
17 Correct 2 ms 1568 KB Output is correct
18 Correct 2 ms 1552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3031 ms 1372 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1564 KB Output is correct
2 Correct 2 ms 1564 KB Output is correct
3 Correct 0 ms 1564 KB Output is correct
4 Correct 45 ms 1496 KB Output is correct
5 Correct 34 ms 1584 KB Output is correct
6 Correct 34 ms 1580 KB Output is correct
7 Correct 35 ms 1584 KB Output is correct
8 Correct 35 ms 1816 KB Output is correct
9 Correct 1293 ms 3132 KB Output is correct
10 Correct 1284 ms 3136 KB Output is correct
11 Correct 1296 ms 3004 KB Output is correct
12 Correct 2 ms 1568 KB Output is correct
13 Correct 1 ms 1556 KB Output is correct
14 Correct 1 ms 1556 KB Output is correct
15 Correct 1 ms 1564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3033 ms 1356 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3069 ms 1372 KB Time limit exceeded
2 Halted 0 ms 0 KB -