답안 #722887

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
722887 2023-04-13T04:38:19 Z The_Samurai Stranded Far From Home (BOI22_island) C++17
10 / 100
1000 ms 28192 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());
    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';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 2 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 4 ms 340 KB Output is correct
8 Correct 3 ms 340 KB Output is correct
9 Correct 2 ms 504 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 1 ms 468 KB Output is correct
14 Correct 27 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 452 ms 12416 KB Output is correct
4 Correct 231 ms 24468 KB Output is correct
5 Correct 199 ms 16180 KB Output is correct
6 Correct 226 ms 16608 KB Output is correct
7 Correct 215 ms 16644 KB Output is correct
8 Correct 225 ms 16716 KB Output is correct
9 Correct 169 ms 16568 KB Output is correct
10 Correct 133 ms 16704 KB Output is correct
11 Correct 101 ms 16452 KB Output is correct
12 Correct 173 ms 15324 KB Output is correct
13 Correct 197 ms 25104 KB Output is correct
14 Correct 219 ms 24292 KB Output is correct
15 Correct 407 ms 16888 KB Output is correct
16 Execution timed out 1053 ms 16068 KB Time limit exceeded
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 169 ms 12080 KB Output is correct
3 Correct 203 ms 16840 KB Output is correct
4 Correct 123 ms 16628 KB Output is correct
5 Correct 192 ms 22136 KB Output is correct
6 Correct 210 ms 16600 KB Output is correct
7 Correct 183 ms 16680 KB Output is correct
8 Correct 206 ms 16716 KB Output is correct
9 Execution timed out 1086 ms 15940 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 221 ms 12164 KB Output is correct
3 Correct 268 ms 16572 KB Output is correct
4 Correct 219 ms 16720 KB Output is correct
5 Correct 134 ms 16696 KB Output is correct
6 Correct 136 ms 16028 KB Output is correct
7 Correct 239 ms 28192 KB Output is correct
8 Execution timed out 1020 ms 26540 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 2 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 4 ms 340 KB Output is correct
8 Correct 3 ms 340 KB Output is correct
9 Correct 2 ms 504 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 1 ms 468 KB Output is correct
14 Correct 27 ms 468 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 452 ms 12416 KB Output is correct
18 Correct 231 ms 24468 KB Output is correct
19 Correct 199 ms 16180 KB Output is correct
20 Correct 226 ms 16608 KB Output is correct
21 Correct 215 ms 16644 KB Output is correct
22 Correct 225 ms 16716 KB Output is correct
23 Correct 169 ms 16568 KB Output is correct
24 Correct 133 ms 16704 KB Output is correct
25 Correct 101 ms 16452 KB Output is correct
26 Correct 173 ms 15324 KB Output is correct
27 Correct 197 ms 25104 KB Output is correct
28 Correct 219 ms 24292 KB Output is correct
29 Correct 407 ms 16888 KB Output is correct
30 Execution timed out 1053 ms 16068 KB Time limit exceeded
31 Halted 0 ms 0 KB -