답안 #722606

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
722606 2023-04-12T12:26:42 Z Itamar Stranded Far From Home (BOI22_island) C++14
100 / 100
582 ms 65204 KB
// ConsoleApplication134.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
using namespace std;
#include <vector>
#define vi vector<int>
#define pi pair<int,int>
#define ll long long
#include <algorithm>
#include <queue>
#define pll pair<ll,ll>
const int siz = 2e5;
bool ans[siz];
ll cit[siz];
vi fr[siz];
int up[siz];
#include <set>
vector<pll> ord;

int my[siz];
vi col[siz];
ll sum[siz];
set<pll> out[siz];

int num[siz];
void uni(int i, int j) {
    i = my[i], j = my[j];
    if (i == j)return;
    if (col[i].size() < col[j].size())swap(i,j);
    sum[i] += sum[j];
    for (pll p : out[j]) {
        out[i].insert(p);
    }
    for (int v : col[j]) {
        col[i].push_back(v);
        my[v] = i;
    }
}

int main()
{
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        cin >> cit[i];
        ord.push_back({ cit[i],-i });
    }
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        fr[a].push_back(b);
        fr[b].push_back(a);
    }
    sort(ord.begin(), ord.end());
    ans[-ord[n - 1].second] = 1;
    for (int i = 0; i < n; i++) {
        ord[i].second = -ord[i].second;
        num[ord[i].second] = i;
    }
    for (int i = 0; i < n; i++) {
        my[i] = i;
        col[i].push_back(i);
        sum[i] = cit[i];
        
        for (int f : fr[i]) {
            if ( num[f]>num[i]) {
                out[i].insert({ cit[f],f });
            }
        }
    }                
    for (int i = 0; i < n; i++)up[i] = -1;
    for (int i = 0; i < n-1; i++) {
        int j = ord[i].second;
        for (int f : fr[j]) {
            if (out[my[f]].find({ cit[j],j }) != out[my[f]].end()) {
                out[my[f]].erase({ cit[j],j });
            }
        }
        for (int f : fr[j]) {
            if (num[f] < i) {
                uni(j, f);
            }
        }
        if (!out[my[j]].empty()) {
            pll p = *out[my[j]].begin();
            if (p.first <= sum[my[j]]) {
                up[j] = p.second;
            }
        }
    }
    for (int i = n - 2; i >= 0; i--) {
        if (up[ord[i].second] != -1) {
            ans[ord[i].second] = ans[up[ord[i].second]];
        }
    }
    for (int i = 0; i < n; i++)if (ans[i])cout << '1'; else cout << '0';
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 19028 KB Output is correct
2 Correct 9 ms 19028 KB Output is correct
3 Correct 10 ms 19028 KB Output is correct
4 Correct 12 ms 19440 KB Output is correct
5 Correct 13 ms 19412 KB Output is correct
6 Correct 12 ms 19364 KB Output is correct
7 Correct 13 ms 19412 KB Output is correct
8 Correct 12 ms 19412 KB Output is correct
9 Correct 13 ms 19412 KB Output is correct
10 Correct 12 ms 19412 KB Output is correct
11 Correct 11 ms 19412 KB Output is correct
12 Correct 11 ms 19512 KB Output is correct
13 Correct 12 ms 19388 KB Output is correct
14 Correct 12 ms 19412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 19028 KB Output is correct
2 Correct 10 ms 19108 KB Output is correct
3 Correct 320 ms 54972 KB Output is correct
4 Correct 323 ms 54880 KB Output is correct
5 Correct 456 ms 57756 KB Output is correct
6 Correct 442 ms 58960 KB Output is correct
7 Correct 438 ms 58964 KB Output is correct
8 Correct 441 ms 57960 KB Output is correct
9 Correct 328 ms 60568 KB Output is correct
10 Correct 258 ms 53608 KB Output is correct
11 Correct 259 ms 54024 KB Output is correct
12 Correct 419 ms 58272 KB Output is correct
13 Correct 287 ms 54960 KB Output is correct
14 Correct 287 ms 54864 KB Output is correct
15 Correct 316 ms 54976 KB Output is correct
16 Correct 233 ms 54508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 19028 KB Output is correct
2 Correct 491 ms 59900 KB Output is correct
3 Correct 480 ms 60668 KB Output is correct
4 Correct 335 ms 59424 KB Output is correct
5 Correct 291 ms 57824 KB Output is correct
6 Correct 503 ms 65204 KB Output is correct
7 Correct 355 ms 59456 KB Output is correct
8 Correct 365 ms 59444 KB Output is correct
9 Correct 242 ms 58216 KB Output is correct
10 Correct 311 ms 58644 KB Output is correct
11 Correct 338 ms 58208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 19028 KB Output is correct
2 Correct 573 ms 56776 KB Output is correct
3 Correct 555 ms 61788 KB Output is correct
4 Correct 534 ms 63152 KB Output is correct
5 Correct 521 ms 62068 KB Output is correct
6 Correct 500 ms 60576 KB Output is correct
7 Correct 402 ms 60064 KB Output is correct
8 Correct 316 ms 63920 KB Output is correct
9 Correct 366 ms 50688 KB Output is correct
10 Correct 471 ms 61168 KB Output is correct
11 Correct 368 ms 58348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 19028 KB Output is correct
2 Correct 9 ms 19028 KB Output is correct
3 Correct 10 ms 19028 KB Output is correct
4 Correct 12 ms 19440 KB Output is correct
5 Correct 13 ms 19412 KB Output is correct
6 Correct 12 ms 19364 KB Output is correct
7 Correct 13 ms 19412 KB Output is correct
8 Correct 12 ms 19412 KB Output is correct
9 Correct 13 ms 19412 KB Output is correct
10 Correct 12 ms 19412 KB Output is correct
11 Correct 11 ms 19412 KB Output is correct
12 Correct 11 ms 19512 KB Output is correct
13 Correct 12 ms 19388 KB Output is correct
14 Correct 12 ms 19412 KB Output is correct
15 Correct 9 ms 19028 KB Output is correct
16 Correct 10 ms 19108 KB Output is correct
17 Correct 320 ms 54972 KB Output is correct
18 Correct 323 ms 54880 KB Output is correct
19 Correct 456 ms 57756 KB Output is correct
20 Correct 442 ms 58960 KB Output is correct
21 Correct 438 ms 58964 KB Output is correct
22 Correct 441 ms 57960 KB Output is correct
23 Correct 328 ms 60568 KB Output is correct
24 Correct 258 ms 53608 KB Output is correct
25 Correct 259 ms 54024 KB Output is correct
26 Correct 419 ms 58272 KB Output is correct
27 Correct 287 ms 54960 KB Output is correct
28 Correct 287 ms 54864 KB Output is correct
29 Correct 316 ms 54976 KB Output is correct
30 Correct 233 ms 54508 KB Output is correct
31 Correct 10 ms 19028 KB Output is correct
32 Correct 491 ms 59900 KB Output is correct
33 Correct 480 ms 60668 KB Output is correct
34 Correct 335 ms 59424 KB Output is correct
35 Correct 291 ms 57824 KB Output is correct
36 Correct 503 ms 65204 KB Output is correct
37 Correct 355 ms 59456 KB Output is correct
38 Correct 365 ms 59444 KB Output is correct
39 Correct 242 ms 58216 KB Output is correct
40 Correct 311 ms 58644 KB Output is correct
41 Correct 338 ms 58208 KB Output is correct
42 Correct 10 ms 19028 KB Output is correct
43 Correct 573 ms 56776 KB Output is correct
44 Correct 555 ms 61788 KB Output is correct
45 Correct 534 ms 63152 KB Output is correct
46 Correct 521 ms 62068 KB Output is correct
47 Correct 500 ms 60576 KB Output is correct
48 Correct 402 ms 60064 KB Output is correct
49 Correct 316 ms 63920 KB Output is correct
50 Correct 366 ms 50688 KB Output is correct
51 Correct 471 ms 61168 KB Output is correct
52 Correct 368 ms 58348 KB Output is correct
53 Correct 10 ms 19048 KB Output is correct
54 Correct 9 ms 19028 KB Output is correct
55 Correct 12 ms 19028 KB Output is correct
56 Correct 13 ms 19428 KB Output is correct
57 Correct 12 ms 19412 KB Output is correct
58 Correct 13 ms 19540 KB Output is correct
59 Correct 14 ms 19460 KB Output is correct
60 Correct 13 ms 19412 KB Output is correct
61 Correct 12 ms 19540 KB Output is correct
62 Correct 13 ms 19512 KB Output is correct
63 Correct 12 ms 19468 KB Output is correct
64 Correct 12 ms 19508 KB Output is correct
65 Correct 12 ms 19412 KB Output is correct
66 Correct 12 ms 19512 KB Output is correct
67 Correct 372 ms 59416 KB Output is correct
68 Correct 295 ms 58032 KB Output is correct
69 Correct 431 ms 61828 KB Output is correct
70 Correct 455 ms 63364 KB Output is correct
71 Correct 450 ms 63092 KB Output is correct
72 Correct 455 ms 62476 KB Output is correct
73 Correct 372 ms 64904 KB Output is correct
74 Correct 264 ms 57360 KB Output is correct
75 Correct 269 ms 57484 KB Output is correct
76 Correct 419 ms 61236 KB Output is correct
77 Correct 279 ms 57804 KB Output is correct
78 Correct 285 ms 57960 KB Output is correct
79 Correct 353 ms 59268 KB Output is correct
80 Correct 235 ms 58260 KB Output is correct
81 Correct 493 ms 64188 KB Output is correct
82 Correct 497 ms 65176 KB Output is correct
83 Correct 326 ms 59312 KB Output is correct
84 Correct 291 ms 57864 KB Output is correct
85 Correct 481 ms 65064 KB Output is correct
86 Correct 353 ms 59408 KB Output is correct
87 Correct 350 ms 59292 KB Output is correct
88 Correct 363 ms 58592 KB Output is correct
89 Correct 389 ms 58288 KB Output is correct
90 Correct 582 ms 61352 KB Output is correct
91 Correct 555 ms 61788 KB Output is correct
92 Correct 554 ms 63136 KB Output is correct
93 Correct 474 ms 62184 KB Output is correct
94 Correct 499 ms 60528 KB Output is correct
95 Correct 416 ms 60124 KB Output is correct
96 Correct 317 ms 63920 KB Output is correct
97 Correct 344 ms 50808 KB Output is correct
98 Correct 488 ms 61048 KB Output is correct
99 Correct 344 ms 58396 KB Output is correct
100 Correct 197 ms 36380 KB Output is correct
101 Correct 567 ms 62796 KB Output is correct
102 Correct 474 ms 60464 KB Output is correct
103 Correct 525 ms 61088 KB Output is correct
104 Correct 581 ms 60776 KB Output is correct