Submission #722890

# Submission time Handle Problem Language Result Execution time Memory
722890 2023-04-13T04:47:38 Z The_Samurai Stranded Far From Home (BOI22_island) C++17
10 / 100
1000 ms 23808 KB
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2")

#include "bits/stdc++.h"

using namespace std;
using ll = long long;
int INF = 2e9;

int n, m, mx;
vector<vector<int>> g;
vector<bool> vis;
vector<int> a;

bool check(int i) {
    int sum = a[i];
    if (sum >= mx) return true;
    priority_queue<pair<int, int>> pq;
    set<int> st = {i};
    vector<int> way = {i};
    for (int u : g[i]) {
        st.insert(u);
        pq.push({-a[u], u});
    }
    while (!pq.empty()) {
        auto [need, u] = pq.top();
        pq.pop();
        need = -need;
        if (sum < need) break;
        way.emplace_back(u);
        sum += need;
        if (sum >= mx) return true;
        for (int v : g[u]) {
            if (!st.count(v)) {
                st.insert(v);
                pq.push({-a[v], v});
            }
        }
    }
    for (int x: way) vis[x] = 1;
    return false;
}

void solve() {
    cin >> n >> m;
    a.assign(n + 1, 0);
    g.assign(n + 1, {});
    vis.assign(n + 1, 0);
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        g[u].emplace_back(v);
        g[v].emplace_back(u);
    }
    mx = *max_element(a.begin() + 1, a.end());
    ll sum = 0;
    for (int x: a) sum += x;
    if (sum - 1ll * count(a.begin(), a.end(), mx) * mx < mx) {
        for (int i = 1; i <= n; i++) {
            cout << (a[i] == mx);
        }
        return;
    }
    for (int i = 1; i <= n; i++) {
        if (vis[i]) {
            cout << 0;
            continue;
        }
        cout << check(i);
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cout.tie(nullptr);
    cin.tie(nullptr);

    int queries = 1;
#ifdef test_cases
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    cin >> queries;
#else
    //    cin >> queries;
#endif

    for (int test_case = 1; test_case <= queries; test_case++) {
        solve();
//        cout << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 3 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 380 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 26 ms 520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 454 ms 12356 KB Output is correct
4 Correct 99 ms 12260 KB Output is correct
5 Correct 169 ms 11856 KB Output is correct
6 Correct 176 ms 12260 KB Output is correct
7 Correct 242 ms 12236 KB Output is correct
8 Correct 184 ms 12312 KB Output is correct
9 Correct 179 ms 12248 KB Output is correct
10 Correct 156 ms 12976 KB Output is correct
11 Correct 87 ms 13004 KB Output is correct
12 Correct 110 ms 12364 KB Output is correct
13 Correct 98 ms 12160 KB Output is correct
14 Correct 132 ms 12236 KB Output is correct
15 Correct 403 ms 12364 KB Output is correct
16 Execution timed out 1072 ms 12224 KB Time limit exceeded
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 215 ms 12188 KB Output is correct
3 Correct 170 ms 12196 KB Output is correct
4 Correct 107 ms 12236 KB Output is correct
5 Correct 142 ms 12236 KB Output is correct
6 Correct 189 ms 12284 KB Output is correct
7 Correct 174 ms 12212 KB Output is correct
8 Correct 165 ms 12224 KB Output is correct
9 Execution timed out 1068 ms 12228 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 223 ms 12208 KB Output is correct
3 Correct 215 ms 12244 KB Output is correct
4 Correct 233 ms 12328 KB Output is correct
5 Correct 135 ms 12208 KB Output is correct
6 Correct 114 ms 11708 KB Output is correct
7 Correct 223 ms 23808 KB Output is correct
8 Execution timed out 1065 ms 23124 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 3 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 380 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 26 ms 520 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 454 ms 12356 KB Output is correct
18 Correct 99 ms 12260 KB Output is correct
19 Correct 169 ms 11856 KB Output is correct
20 Correct 176 ms 12260 KB Output is correct
21 Correct 242 ms 12236 KB Output is correct
22 Correct 184 ms 12312 KB Output is correct
23 Correct 179 ms 12248 KB Output is correct
24 Correct 156 ms 12976 KB Output is correct
25 Correct 87 ms 13004 KB Output is correct
26 Correct 110 ms 12364 KB Output is correct
27 Correct 98 ms 12160 KB Output is correct
28 Correct 132 ms 12236 KB Output is correct
29 Correct 403 ms 12364 KB Output is correct
30 Execution timed out 1072 ms 12224 KB Time limit exceeded
31 Halted 0 ms 0 KB -