답안 #723078

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
723078 2023-04-13T08:21:05 Z dxz05 Stranded Far From Home (BOI22_island) C++17
40 / 100
1000 ms 110756 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define all(x) (x).begin(), (x).end()
#define MP make_pair
const int N = 200500;

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

int s[N];
vector<int> g[N];
bool can[N];

vector<int> comp;
int color[N];

void dfs(int v){
    color[v] = 2;
    comp.push_back(v);
    for (int u : g[v]){
        if (!can[u] && color[u] == 1){
            dfs(u);
        }
    }
}

void go(vector<int> &vertices, long long need){
    long long sum = 0;
    int mx = 0;
    for (int v : vertices){
        sum += s[v];
        mx = max(mx, s[v]);
        color[v] = 1;
    }

    if (sum < need) return;

    for (int v : vertices){
        if (s[v] == mx) can[v] = true;
    }

    vector<vector<int>> components;
    for (int v : vertices){
        if (color[v] == 1 && !can[v]){
            comp.clear();
            dfs(v);
            components.push_back(comp);
        }
    }

    for (auto vec : components){
        go(vec, mx);
    }
}

void solve(){
    int n, m;
    cin >> n >> m;

    for (int i = 0; i < n; i++){
        cin >> s[i];
    }

    while (m--){
        int u, v;
        cin >> u >> v;
        --u, --v;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    ll total = accumulate(s, s + n, 0ll);

    vector<int> vertices(n);
    iota(all(vertices), 0);

    go(vertices, total);

    for (int i = 0; i < n; i++){
        cout << can[i];
    }

}

int main() {
    ios_base::sync_with_stdio(false);

#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    solve();

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Correct 4 ms 4936 KB Output is correct
3 Correct 2 ms 4964 KB Output is correct
4 Correct 23 ms 9884 KB Output is correct
5 Correct 7 ms 5972 KB Output is correct
6 Correct 3 ms 5076 KB Output is correct
7 Correct 22 ms 8956 KB Output is correct
8 Correct 19 ms 8916 KB Output is correct
9 Correct 3 ms 5204 KB Output is correct
10 Correct 4 ms 5204 KB Output is correct
11 Correct 4 ms 5204 KB Output is correct
12 Correct 4 ms 5076 KB Output is correct
13 Correct 3 ms 5204 KB Output is correct
14 Correct 6 ms 6040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Execution timed out 1084 ms 110756 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 340 ms 26272 KB Output is correct
3 Correct 367 ms 32604 KB Output is correct
4 Correct 118 ms 14004 KB Output is correct
5 Correct 147 ms 24024 KB Output is correct
6 Correct 458 ms 35344 KB Output is correct
7 Execution timed out 1062 ms 90044 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Correct 204 ms 15808 KB Output is correct
3 Correct 204 ms 15700 KB Output is correct
4 Correct 202 ms 15812 KB Output is correct
5 Correct 118 ms 14208 KB Output is correct
6 Correct 134 ms 13732 KB Output is correct
7 Correct 107 ms 17160 KB Output is correct
8 Correct 88 ms 23276 KB Output is correct
9 Correct 85 ms 11084 KB Output is correct
10 Correct 156 ms 16236 KB Output is correct
11 Correct 183 ms 30120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Correct 4 ms 4936 KB Output is correct
3 Correct 2 ms 4964 KB Output is correct
4 Correct 23 ms 9884 KB Output is correct
5 Correct 7 ms 5972 KB Output is correct
6 Correct 3 ms 5076 KB Output is correct
7 Correct 22 ms 8956 KB Output is correct
8 Correct 19 ms 8916 KB Output is correct
9 Correct 3 ms 5204 KB Output is correct
10 Correct 4 ms 5204 KB Output is correct
11 Correct 4 ms 5204 KB Output is correct
12 Correct 4 ms 5076 KB Output is correct
13 Correct 3 ms 5204 KB Output is correct
14 Correct 6 ms 6040 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Execution timed out 1084 ms 110756 KB Time limit exceeded
18 Halted 0 ms 0 KB -