답안 #603618

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
603618 2022-07-24T08:59:48 Z shrimb Stranded Far From Home (BOI22_island) C++17
0 / 100
303 ms 13788 KB
#include"bits/stdc++.h"
using namespace std;
const int maxn = 200001;

vector<int> adj[maxn];
bitset<maxn> vis;
signed main () {
    int n, m;
    cin >> n >> m;
    int a[n + 1];
    for (int i = 1 ; i <= n ; i++) cin >> a[i];
    for (int i = 0 ; i < m ; i++) {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    int v[n + 1];
    for (int i = 1 ; i <= n ; i++) {
        v[i] = i;
        sort(adj[i].begin(), adj[i].end(), [&](int x, int y){return a[x] < a[y];});
    }
    int p[n + 1];
    sort(v + 1, v + 1 + n, [&](int i, int j){return a[adj[i][0]] > a[adj[j][0]];});
    for (int i = 1 ; i <= n ; i++) {
        p[v[i]] = i;
    }
    int l = 0, r = n + 1;
    while (r - l > 1) {
        int m = (l + r) / 2;
        // cerr << "m: " << m << endl;
        priority_queue<pair<int,int>> pq; // {-value, index}
        int cur = a[v[m]];
        pq.push({0, v[m]});
        vis = 0;
        vis[v[m]] = 1;
        int good = 0;
        while (pq.size()) {
            auto [v, i] = pq.top();
            pq.pop();
            v *= -1;
            if (cur >= v) {
                cur += v;
                // cerr << "i: " << i << "\n";
                good++;
            } else {
                continue;
            }
            for (int j : adj[i]) {
                if (!vis[j]) {
                    vis[j] = 1;
                    pq.emplace(-a[j], j);
                }
            }
        }
        // cerr << good << endl;
        if (good == n) r = m;
        else l = m;
    }
    // cerr << "l: " << l << endl;
    // for (int i = 1 ; i <= n ; i++) cout << p[i] << " ";
    // cout << endl;
    for (int i = 1 ; i <= n ; i++) {

        if (p[i] <= l) cout << 0;
        else cout << 1;
    }
    cout << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Incorrect 5 ms 5076 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Incorrect 276 ms 13760 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Incorrect 303 ms 13688 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Incorrect 296 ms 13788 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Incorrect 5 ms 5076 KB Output isn't correct
5 Halted 0 ms 0 KB -