# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
614230 | 2022-07-30T22:42:51 Z | Plurm | Stranded Far From Home (BOI22_island) | C++11 | 129 ms | 15660 KB |
#include <bits/stdc++.h> using namespace std; int s[200005]; vector<int> g[200005]; int n, m; bool check(int u) { priority_queue<pair<int, int>> pq; int allies = s[u]; set<int> alliance = {u}; for (int v : g[u]) pq.push({-s[v], v}); while (!pq.empty()) { int vnxt = pq.top().second; pq.pop(); if (alliance.count(vnxt)) continue; if (s[vnxt] <= allies) { allies += s[vnxt]; alliance.insert(vnxt); for (int v : g[vnxt]) { if (!alliance.count(v)) { pq.push({-s[v], v}); } } } } return alliance.size() == n; } int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%d", s + i); } for (int i = 0; i < m; i++) { int u, v; scanf("%d%d", &u, &v); g[u].push_back(v); g[v].push_back(u); } if (n > 2000) { int lo = 1; int hi = n; int mid; while (lo < hi) { mid = (lo + hi) / 2; if (check(mid)) { lo = mid + 1; } else { hi = mid; } } if (check(lo)) { for (int i = 1; i <= n; i++) printf("1"); printf("\n"); } else { for (int i = 1; i <= lo; i++) printf("1"); for (int i = lo + 1; i <= n; i++) printf("0"); printf("\n"); } } else { for (int i = 1; i <= n; i++) { if (check(i)) printf("1"); else printf("0"); } printf("\n"); } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4948 KB | Output is correct |
2 | Correct | 4 ms | 5000 KB | Output is correct |
3 | Correct | 3 ms | 4948 KB | Output is correct |
4 | Incorrect | 6 ms | 5076 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 4948 KB | Output is correct |
2 | Correct | 3 ms | 5004 KB | Output is correct |
3 | Incorrect | 114 ms | 14960 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4948 KB | Output is correct |
2 | Incorrect | 129 ms | 15508 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 5008 KB | Output is correct |
2 | Incorrect | 128 ms | 15660 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4948 KB | Output is correct |
2 | Correct | 4 ms | 5000 KB | Output is correct |
3 | Correct | 3 ms | 4948 KB | Output is correct |
4 | Incorrect | 6 ms | 5076 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |