답안 #255305

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
255305 2020-07-31T17:15:03 Z model_code Aesthetic (NOI20_aesthetic) C++17
100 / 100
852 ms 34680 KB
#include <bits/stdc++.h>
using namespace std;

long long r[2][300000];
bool vt[300000], f[300000];
int A[300000][4], p[300000], q[300000], d[300000], id[300000];
vector<pair<pair<int, int>, int> > adj[300000];
priority_queue<pair<pair<long long, int>, pair<int, int> > > pq;

int frt(int i) {return i == id[i] ? i : id[i] = frt(id[i]);}

void it(int i, int t, int o, int l, long long v) {
    if (vt[i]) return;
    vt[i] = 1;
    if (!t) {p[i] = o; q[i] = l; d[i] = d[o] + !!i;}
    r[t][i] = v;
    for (int j = 0; j < adj[i].size(); ++j) if (!vt[adj[i][j].first.first]) pq.emplace(make_pair(-v - adj[i][j].first.second, adj[i][j].first.first), make_pair(i, adj[i][j].second));
}

int main() {
    //freopen("in.txt", "r", stdin);
    int N, M, a, b, x, i, j;
    long long l, h, c;
    bool e;
    scanf("%d %d", &N, &M);
    for (i = 0; i < M; ++i) {for (j = 0; j < 3; ++j) scanf("%d", &A[i][j]); adj[--A[i][0]].emplace_back(make_pair(--A[i][1], A[i][2]), i); adj[A[i][1]].emplace_back(make_pair(A[i][0], A[i][2]), i);}
    for (i = M - 2; i > -1; --i) A[i][3] = max(A[i + 1][2], A[i + 1][3]);
    it(0, 0, 0, -1, 0);
    while (!pq.empty()) x = pq.top().first.second, c = -pq.top().first.first, a = pq.top().second.first, b = pq.top().second.second, pq.pop(), it(x, 0, a, b, c);
    memset(vt, 0, sizeof(vt));
    it(N - 1, 1, N - 1, -1, 0);
    while (!pq.empty()) x = pq.top().first.second, c = -pq.top().first.first, a = pq.top().second.first, b = pq.top().second.second, pq.pop(), it(x, 1, a, b, c);
    h = (l = r[0][N - 1]) + 1000000000;
    //for (i = 0; i < M; ++i) printf("%d: %d %d %d %d\n", i, A[i][0], A[i][1], A[i][2], A[i][3]);
    while (l < h) {
        e = 0;
        c = (l + h + 1) / 2;
        //printf("%lld %lld %lld:\n", l, h, c);
        for (i = 0; i < N; ++i) {id[i] = p[i]; if (i) f[q[i]] = 1;}
        for (i = N - 1; i; i = p[i]) id[i] = i;
        for (i = 0; i < M; ++i) if (!f[i] && (r[0][A[i][0]] + A[i][2] + r[1][A[i][1]] < c || r[0][A[i][1]] + A[i][2] + r[1][A[i][0]] < c)) {
            a = frt(A[i][0]);
            b = frt(A[i][1]);
            if (d[a] > d[b]) swap(a, b);
            //printf("%d %d | %d %d\n", a, b, d[a], d[b]);
            while (a != b) id[b] = p[b], b = frt(b);
        }
        for (i = frt(N - 1); i && !e; i = frt(p[i])) e = (c <= r[0][A[q[i]][0]] + A[q[i]][2] + A[q[i]][3] + r[1][A[q[i]][1]] && c <= r[0][A[q[i]][1]] + A[q[i]][2] + A[q[i]][3] + r[1][A[q[i]][0]]);
        //for (i = frt(N - 1); i; i = frt(p[i])) printf("! %d _ %d %d %d (%d)\n", q[i], A[q[i]][0], A[q[i]][1], A[q[i]][2], A[q[i]][3]);
        (e ? l : h) = c - !e;
        //printf("\n");
    }
    printf("%lld", (l + h) / 2);
    return 0;
}

Compilation message

Aesthetic.cpp: In function 'void it(int, int, int, int, long long int)':
Aesthetic.cpp:17:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int j = 0; j < adj[i].size(); ++j) if (!vt[adj[i][j].first.first]) pq.emplace(make_pair(-v - adj[i][j].first.second, adj[i][j].first.first), make_pair(i, adj[i][j].second));
                     ~~^~~~~~~~~~~~~~~
Aesthetic.cpp: In function 'int main()':
Aesthetic.cpp:25:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &N, &M);
     ~~~~~^~~~~~~~~~~~~~~~~
Aesthetic.cpp:26:59: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for (i = 0; i < M; ++i) {for (j = 0; j < 3; ++j) scanf("%d", &A[i][j]); adj[--A[i][0]].emplace_back(make_pair(--A[i][1], A[i][2]), i); adj[A[i][1]].emplace_back(make_pair(A[i][0], A[i][2]), i);}
                                                      ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7680 KB Output is correct
2 Correct 5 ms 7680 KB Output is correct
3 Correct 5 ms 7680 KB Output is correct
4 Correct 5 ms 7680 KB Output is correct
5 Correct 6 ms 7680 KB Output is correct
6 Correct 5 ms 7680 KB Output is correct
7 Correct 6 ms 7680 KB Output is correct
8 Correct 5 ms 7680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7680 KB Output is correct
2 Correct 5 ms 7680 KB Output is correct
3 Correct 5 ms 7680 KB Output is correct
4 Correct 5 ms 7680 KB Output is correct
5 Correct 6 ms 7680 KB Output is correct
6 Correct 5 ms 7680 KB Output is correct
7 Correct 6 ms 7680 KB Output is correct
8 Correct 5 ms 7680 KB Output is correct
9 Correct 8 ms 7868 KB Output is correct
10 Correct 8 ms 7936 KB Output is correct
11 Correct 7 ms 7808 KB Output is correct
12 Correct 8 ms 7808 KB Output is correct
13 Correct 8 ms 7808 KB Output is correct
14 Correct 7 ms 7856 KB Output is correct
15 Correct 6 ms 7808 KB Output is correct
16 Correct 7 ms 7936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 562 ms 34168 KB Output is correct
2 Correct 568 ms 34352 KB Output is correct
3 Correct 584 ms 34008 KB Output is correct
4 Correct 630 ms 33968 KB Output is correct
5 Correct 658 ms 34088 KB Output is correct
6 Correct 613 ms 34604 KB Output is correct
7 Correct 579 ms 34552 KB Output is correct
8 Correct 587 ms 34680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 688 ms 34556 KB Output is correct
2 Correct 684 ms 34296 KB Output is correct
3 Correct 678 ms 34168 KB Output is correct
4 Correct 718 ms 34680 KB Output is correct
5 Correct 682 ms 34168 KB Output is correct
6 Correct 667 ms 34272 KB Output is correct
7 Correct 594 ms 34368 KB Output is correct
8 Correct 582 ms 34424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 713 ms 33124 KB Output is correct
2 Correct 394 ms 30328 KB Output is correct
3 Correct 541 ms 27996 KB Output is correct
4 Correct 537 ms 28280 KB Output is correct
5 Correct 513 ms 28152 KB Output is correct
6 Correct 538 ms 28112 KB Output is correct
7 Correct 499 ms 27892 KB Output is correct
8 Correct 494 ms 28152 KB Output is correct
9 Correct 491 ms 28152 KB Output is correct
10 Correct 491 ms 28280 KB Output is correct
11 Correct 493 ms 28280 KB Output is correct
12 Correct 717 ms 33508 KB Output is correct
13 Correct 506 ms 28208 KB Output is correct
14 Correct 307 ms 31480 KB Output is correct
15 Correct 300 ms 33068 KB Output is correct
16 Correct 852 ms 33632 KB Output is correct
17 Correct 743 ms 32852 KB Output is correct
18 Correct 732 ms 33244 KB Output is correct
19 Correct 384 ms 30328 KB Output is correct
20 Correct 401 ms 30188 KB Output is correct
21 Correct 389 ms 30200 KB Output is correct
22 Correct 387 ms 30200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 713 ms 33124 KB Output is correct
2 Correct 394 ms 30328 KB Output is correct
3 Correct 541 ms 27996 KB Output is correct
4 Correct 537 ms 28280 KB Output is correct
5 Correct 513 ms 28152 KB Output is correct
6 Correct 538 ms 28112 KB Output is correct
7 Correct 499 ms 27892 KB Output is correct
8 Correct 494 ms 28152 KB Output is correct
9 Correct 491 ms 28152 KB Output is correct
10 Correct 491 ms 28280 KB Output is correct
11 Correct 493 ms 28280 KB Output is correct
12 Correct 717 ms 33508 KB Output is correct
13 Correct 506 ms 28208 KB Output is correct
14 Correct 307 ms 31480 KB Output is correct
15 Correct 300 ms 33068 KB Output is correct
16 Correct 852 ms 33632 KB Output is correct
17 Correct 743 ms 32852 KB Output is correct
18 Correct 732 ms 33244 KB Output is correct
19 Correct 384 ms 30328 KB Output is correct
20 Correct 401 ms 30188 KB Output is correct
21 Correct 389 ms 30200 KB Output is correct
22 Correct 387 ms 30200 KB Output is correct
23 Correct 814 ms 33740 KB Output is correct
24 Correct 412 ms 30456 KB Output is correct
25 Correct 519 ms 28024 KB Output is correct
26 Correct 496 ms 28132 KB Output is correct
27 Correct 536 ms 28024 KB Output is correct
28 Correct 533 ms 28024 KB Output is correct
29 Correct 500 ms 28152 KB Output is correct
30 Correct 519 ms 27952 KB Output is correct
31 Correct 509 ms 28380 KB Output is correct
32 Correct 531 ms 28376 KB Output is correct
33 Correct 502 ms 28152 KB Output is correct
34 Correct 760 ms 33636 KB Output is correct
35 Correct 492 ms 28280 KB Output is correct
36 Correct 360 ms 32152 KB Output is correct
37 Correct 352 ms 32552 KB Output is correct
38 Correct 739 ms 33376 KB Output is correct
39 Correct 744 ms 33120 KB Output is correct
40 Correct 745 ms 33668 KB Output is correct
41 Correct 417 ms 30328 KB Output is correct
42 Correct 442 ms 30408 KB Output is correct
43 Correct 433 ms 30272 KB Output is correct
44 Correct 424 ms 30200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7680 KB Output is correct
2 Correct 5 ms 7680 KB Output is correct
3 Correct 5 ms 7680 KB Output is correct
4 Correct 5 ms 7680 KB Output is correct
5 Correct 6 ms 7680 KB Output is correct
6 Correct 5 ms 7680 KB Output is correct
7 Correct 6 ms 7680 KB Output is correct
8 Correct 5 ms 7680 KB Output is correct
9 Correct 8 ms 7868 KB Output is correct
10 Correct 8 ms 7936 KB Output is correct
11 Correct 7 ms 7808 KB Output is correct
12 Correct 8 ms 7808 KB Output is correct
13 Correct 8 ms 7808 KB Output is correct
14 Correct 7 ms 7856 KB Output is correct
15 Correct 6 ms 7808 KB Output is correct
16 Correct 7 ms 7936 KB Output is correct
17 Correct 562 ms 34168 KB Output is correct
18 Correct 568 ms 34352 KB Output is correct
19 Correct 584 ms 34008 KB Output is correct
20 Correct 630 ms 33968 KB Output is correct
21 Correct 658 ms 34088 KB Output is correct
22 Correct 613 ms 34604 KB Output is correct
23 Correct 579 ms 34552 KB Output is correct
24 Correct 587 ms 34680 KB Output is correct
25 Correct 688 ms 34556 KB Output is correct
26 Correct 684 ms 34296 KB Output is correct
27 Correct 678 ms 34168 KB Output is correct
28 Correct 718 ms 34680 KB Output is correct
29 Correct 682 ms 34168 KB Output is correct
30 Correct 667 ms 34272 KB Output is correct
31 Correct 594 ms 34368 KB Output is correct
32 Correct 582 ms 34424 KB Output is correct
33 Correct 713 ms 33124 KB Output is correct
34 Correct 394 ms 30328 KB Output is correct
35 Correct 541 ms 27996 KB Output is correct
36 Correct 537 ms 28280 KB Output is correct
37 Correct 513 ms 28152 KB Output is correct
38 Correct 538 ms 28112 KB Output is correct
39 Correct 499 ms 27892 KB Output is correct
40 Correct 494 ms 28152 KB Output is correct
41 Correct 491 ms 28152 KB Output is correct
42 Correct 491 ms 28280 KB Output is correct
43 Correct 493 ms 28280 KB Output is correct
44 Correct 717 ms 33508 KB Output is correct
45 Correct 506 ms 28208 KB Output is correct
46 Correct 307 ms 31480 KB Output is correct
47 Correct 300 ms 33068 KB Output is correct
48 Correct 852 ms 33632 KB Output is correct
49 Correct 743 ms 32852 KB Output is correct
50 Correct 732 ms 33244 KB Output is correct
51 Correct 384 ms 30328 KB Output is correct
52 Correct 401 ms 30188 KB Output is correct
53 Correct 389 ms 30200 KB Output is correct
54 Correct 387 ms 30200 KB Output is correct
55 Correct 814 ms 33740 KB Output is correct
56 Correct 412 ms 30456 KB Output is correct
57 Correct 519 ms 28024 KB Output is correct
58 Correct 496 ms 28132 KB Output is correct
59 Correct 536 ms 28024 KB Output is correct
60 Correct 533 ms 28024 KB Output is correct
61 Correct 500 ms 28152 KB Output is correct
62 Correct 519 ms 27952 KB Output is correct
63 Correct 509 ms 28380 KB Output is correct
64 Correct 531 ms 28376 KB Output is correct
65 Correct 502 ms 28152 KB Output is correct
66 Correct 760 ms 33636 KB Output is correct
67 Correct 492 ms 28280 KB Output is correct
68 Correct 360 ms 32152 KB Output is correct
69 Correct 352 ms 32552 KB Output is correct
70 Correct 739 ms 33376 KB Output is correct
71 Correct 744 ms 33120 KB Output is correct
72 Correct 745 ms 33668 KB Output is correct
73 Correct 417 ms 30328 KB Output is correct
74 Correct 442 ms 30408 KB Output is correct
75 Correct 433 ms 30272 KB Output is correct
76 Correct 424 ms 30200 KB Output is correct
77 Correct 658 ms 33892 KB Output is correct
78 Correct 375 ms 30200 KB Output is correct
79 Correct 473 ms 28152 KB Output is correct
80 Correct 456 ms 28024 KB Output is correct
81 Correct 450 ms 28280 KB Output is correct
82 Correct 435 ms 28024 KB Output is correct
83 Correct 438 ms 28280 KB Output is correct
84 Correct 444 ms 28268 KB Output is correct
85 Correct 432 ms 28152 KB Output is correct
86 Correct 444 ms 28360 KB Output is correct
87 Correct 458 ms 28164 KB Output is correct
88 Correct 670 ms 33552 KB Output is correct
89 Correct 447 ms 28536 KB Output is correct
90 Correct 371 ms 32024 KB Output is correct
91 Correct 368 ms 32288 KB Output is correct
92 Correct 740 ms 33916 KB Output is correct
93 Correct 639 ms 33376 KB Output is correct
94 Correct 635 ms 33248 KB Output is correct
95 Correct 372 ms 30328 KB Output is correct
96 Correct 370 ms 30328 KB Output is correct
97 Correct 372 ms 30200 KB Output is correct
98 Correct 368 ms 30200 KB Output is correct