답안 #1008930

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1008930 2024-06-27T05:42:41 Z 12345678 봉쇄 시간 (IOI23_closing) C++17
30 / 100
1000 ms 38080 KB
#include "closing.h"
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#pragma gcc-optimize("O3, unrolls-loops")

const int nx=2e5+5;

vector<pair<ll, ll>> g[nx];

void dfs(int u, int p, ll cw, vector<ll> &pa, vector<ll> &x)
{
    pa[u]=p;
    x[u]=cw;
    for (auto [v, w]:g[u]) if (v!=p) dfs(v, u, cw+w, pa, x);
}

int max_score(int N, int X, int Y, long long K,
              std::vector<int> U, std::vector<int> V, std::vector<int> W)
{
    ll mx=0;
    for (int i=0; i<N; i++) g[i].clear();
    for (int i=0; i<N-1; i++) g[U[i]].push_back({V[i], W[i]}), g[V[i]].push_back({U[i], W[i]});
    vector<ll> pa(N), pb(N), a(N), b(N);
    dfs(X, X, 0, pa, a);
    dfs(Y, Y, 0, pb, b);
    priority_queue<ll, vector<ll>, greater<ll>> pq2;
    for (int i=0; i<N; i++) pq2.push(a[i]), pq2.push(b[i]);
    ll tmp=K;
    while (!pq2.empty()&&pq2.top()<=tmp) mx++, tmp-=pq2.top(), pq2.pop();
    vector<ll> path;
    tmp=Y;
    while (tmp!=X) path.push_back(tmp), tmp=pa[tmp];
    path.push_back(X);
    reverse(path.begin(), path.end());
    ll sz=path.size();
    for (int i=0; i<sz; i++)
    {
        for (int j=i; j<sz; j++)
        {
            ll c=K, res=0;
            priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq;
            vector<ll> vs(N);
            for (int k=i; k<=j; k++) vs[path[k]]=1, c-=max(a[path[k]], b[path[k]]), res+=2;
            for (int k=0; k<i; k++) vs[path[k]]=1, res++, c-=a[path[k]];
            for (int k=j+1; k<sz; k++) vs[path[k]]=1, res++, c-=b[path[k]];
            for (int k=i; k<=j; k++) for (auto [v, w]:g[path[k]]) if (!vs[v]) pq.push({max(a[v], b[v]), v});
            if (c<0) continue;
            while (!pq2.empty()) pq2.pop();
            for (int i=0; i<N; i++) if (!vs[i]) pq2.push(a[i]), pq2.push(b[i]);
            ll tmpres=res, tmpc=c;
            while (!pq2.empty()&&tmpc>=pq2.top()) tmpres++, tmpc-=pq2.top(), pq2.pop();
            mx=max(mx, tmpres);
            while (!pq.empty())
            {
                auto [w, u]=pq.top();
                pq.pop();
                c-=w;
                vs[u]=1;
                res+=2;
                for (auto [v, cw]:g[u]) if (!vs[v]) pq.push({max(a[v], b[v]), v});
                if (c<0) continue;
                while (!pq2.empty()) pq2.pop();
                for (int i=0; i<N; i++) if (!vs[i]) pq2.push(a[i]), pq2.push(b[i]);
                tmpres=res, tmpc=c;
                while (!pq2.empty()&&tmpc>=pq2.top()) tmpres++, tmpc-=pq2.top(), pq2.pop();
                mx=max(mx, tmpres);
            }
        }
    }
    return mx;
}

/*
1
6 0 3 20
0 1 2
1 2 5
2 3 6
1 4 5
1 5 2
*/

Compilation message

closing.cpp:7: warning: ignoring '#pragma gcc ' [-Wunknown-pragmas]
    7 | #pragma gcc-optimize("O3, unrolls-loops")
      |
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1043 ms 38080 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4952 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 1 ms 4956 KB Output is correct
8 Correct 1 ms 4956 KB Output is correct
9 Correct 1 ms 4952 KB Output is correct
10 Correct 1 ms 4948 KB Output is correct
11 Correct 1 ms 4956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4952 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 1 ms 4956 KB Output is correct
8 Correct 1 ms 4956 KB Output is correct
9 Correct 1 ms 4952 KB Output is correct
10 Correct 1 ms 4948 KB Output is correct
11 Correct 1 ms 4956 KB Output is correct
12 Correct 2 ms 4952 KB Output is correct
13 Correct 1 ms 4956 KB Output is correct
14 Correct 3 ms 4956 KB Output is correct
15 Correct 1 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 1 ms 4956 KB Output is correct
19 Correct 36 ms 5220 KB Output is correct
20 Correct 2 ms 5212 KB Output is correct
21 Correct 653 ms 5212 KB Output is correct
22 Correct 11 ms 5212 KB Output is correct
23 Correct 209 ms 5212 KB Output is correct
24 Correct 103 ms 5212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4952 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 1 ms 4956 KB Output is correct
8 Correct 1 ms 4956 KB Output is correct
9 Correct 1 ms 4952 KB Output is correct
10 Correct 1 ms 4948 KB Output is correct
11 Correct 1 ms 4956 KB Output is correct
12 Correct 2 ms 4952 KB Output is correct
13 Correct 1 ms 4956 KB Output is correct
14 Correct 3 ms 4956 KB Output is correct
15 Correct 1 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 1 ms 4956 KB Output is correct
19 Correct 36 ms 5220 KB Output is correct
20 Correct 2 ms 5212 KB Output is correct
21 Correct 653 ms 5212 KB Output is correct
22 Correct 11 ms 5212 KB Output is correct
23 Correct 209 ms 5212 KB Output is correct
24 Correct 103 ms 5212 KB Output is correct
25 Correct 23 ms 4956 KB Output is correct
26 Execution timed out 1050 ms 5464 KB Time limit exceeded
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5208 KB Output is correct
2 Correct 1 ms 4952 KB Output is correct
3 Correct 1 ms 4952 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 1 ms 4956 KB Output is correct
8 Correct 1 ms 4956 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Correct 1 ms 4956 KB Output is correct
11 Correct 1 ms 4956 KB Output is correct
12 Correct 1 ms 4956 KB Output is correct
13 Correct 1 ms 4956 KB Output is correct
14 Correct 1 ms 4956 KB Output is correct
15 Correct 1 ms 4956 KB Output is correct
16 Correct 1 ms 4956 KB Output is correct
17 Correct 1 ms 4956 KB Output is correct
18 Correct 1 ms 4956 KB Output is correct
19 Correct 1 ms 4956 KB Output is correct
20 Correct 1 ms 4952 KB Output is correct
21 Correct 1 ms 4952 KB Output is correct
22 Correct 1 ms 4956 KB Output is correct
23 Correct 1 ms 4952 KB Output is correct
24 Correct 1 ms 4956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5208 KB Output is correct
2 Correct 1 ms 4952 KB Output is correct
3 Correct 1 ms 4952 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 1 ms 4956 KB Output is correct
8 Correct 1 ms 4956 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Correct 1 ms 4952 KB Output is correct
11 Correct 1 ms 4948 KB Output is correct
12 Correct 1 ms 4956 KB Output is correct
13 Correct 2 ms 4952 KB Output is correct
14 Correct 1 ms 4956 KB Output is correct
15 Correct 3 ms 4956 KB Output is correct
16 Correct 1 ms 4956 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 1 ms 4956 KB Output is correct
20 Correct 1 ms 4956 KB Output is correct
21 Correct 1 ms 4956 KB Output is correct
22 Correct 1 ms 4956 KB Output is correct
23 Correct 1 ms 4956 KB Output is correct
24 Correct 1 ms 4956 KB Output is correct
25 Correct 1 ms 4956 KB Output is correct
26 Correct 1 ms 4956 KB Output is correct
27 Correct 1 ms 4956 KB Output is correct
28 Correct 1 ms 4956 KB Output is correct
29 Correct 1 ms 4956 KB Output is correct
30 Correct 1 ms 4956 KB Output is correct
31 Correct 1 ms 4956 KB Output is correct
32 Correct 1 ms 4952 KB Output is correct
33 Correct 1 ms 4952 KB Output is correct
34 Correct 1 ms 4956 KB Output is correct
35 Correct 1 ms 4952 KB Output is correct
36 Correct 1 ms 4956 KB Output is correct
37 Correct 1 ms 4952 KB Output is correct
38 Incorrect 2 ms 4956 KB 1st lines differ - on the 1st token, expected: '41', found: '40'
39 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5208 KB Output is correct
2 Correct 1 ms 4952 KB Output is correct
3 Correct 1 ms 4952 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 1 ms 4956 KB Output is correct
8 Correct 1 ms 4956 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Correct 1 ms 4952 KB Output is correct
11 Correct 1 ms 4948 KB Output is correct
12 Correct 1 ms 4956 KB Output is correct
13 Correct 2 ms 4952 KB Output is correct
14 Correct 1 ms 4956 KB Output is correct
15 Correct 3 ms 4956 KB Output is correct
16 Correct 1 ms 4956 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 1 ms 4956 KB Output is correct
20 Correct 36 ms 5220 KB Output is correct
21 Correct 2 ms 5212 KB Output is correct
22 Correct 653 ms 5212 KB Output is correct
23 Correct 11 ms 5212 KB Output is correct
24 Correct 209 ms 5212 KB Output is correct
25 Correct 103 ms 5212 KB Output is correct
26 Correct 1 ms 4956 KB Output is correct
27 Correct 1 ms 4956 KB Output is correct
28 Correct 1 ms 4956 KB Output is correct
29 Correct 1 ms 4956 KB Output is correct
30 Correct 1 ms 4956 KB Output is correct
31 Correct 1 ms 4956 KB Output is correct
32 Correct 1 ms 4956 KB Output is correct
33 Correct 1 ms 4956 KB Output is correct
34 Correct 1 ms 4956 KB Output is correct
35 Correct 1 ms 4956 KB Output is correct
36 Correct 1 ms 4956 KB Output is correct
37 Correct 1 ms 4956 KB Output is correct
38 Correct 1 ms 4956 KB Output is correct
39 Correct 1 ms 4952 KB Output is correct
40 Correct 1 ms 4952 KB Output is correct
41 Correct 1 ms 4956 KB Output is correct
42 Correct 1 ms 4952 KB Output is correct
43 Correct 1 ms 4956 KB Output is correct
44 Correct 1 ms 4952 KB Output is correct
45 Incorrect 2 ms 4956 KB 1st lines differ - on the 1st token, expected: '41', found: '40'
46 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5208 KB Output is correct
2 Correct 1 ms 4952 KB Output is correct
3 Correct 1 ms 4952 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 1 ms 4956 KB Output is correct
8 Correct 1 ms 4956 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Correct 1 ms 4952 KB Output is correct
11 Correct 1 ms 4948 KB Output is correct
12 Correct 1 ms 4956 KB Output is correct
13 Correct 2 ms 4952 KB Output is correct
14 Correct 1 ms 4956 KB Output is correct
15 Correct 3 ms 4956 KB Output is correct
16 Correct 1 ms 4956 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 1 ms 4956 KB Output is correct
20 Correct 36 ms 5220 KB Output is correct
21 Correct 2 ms 5212 KB Output is correct
22 Correct 653 ms 5212 KB Output is correct
23 Correct 11 ms 5212 KB Output is correct
24 Correct 209 ms 5212 KB Output is correct
25 Correct 103 ms 5212 KB Output is correct
26 Correct 23 ms 4956 KB Output is correct
27 Execution timed out 1050 ms 5464 KB Time limit exceeded
28 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5208 KB Output is correct
2 Correct 1 ms 4952 KB Output is correct
3 Correct 1 ms 4952 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 1 ms 4956 KB Output is correct
8 Correct 1 ms 4956 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Correct 1 ms 4952 KB Output is correct
11 Correct 1 ms 4948 KB Output is correct
12 Correct 1 ms 4956 KB Output is correct
13 Correct 2 ms 4952 KB Output is correct
14 Correct 1 ms 4956 KB Output is correct
15 Correct 3 ms 4956 KB Output is correct
16 Correct 1 ms 4956 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 1 ms 4956 KB Output is correct
20 Correct 36 ms 5220 KB Output is correct
21 Correct 2 ms 5212 KB Output is correct
22 Correct 653 ms 5212 KB Output is correct
23 Correct 11 ms 5212 KB Output is correct
24 Correct 209 ms 5212 KB Output is correct
25 Correct 103 ms 5212 KB Output is correct
26 Correct 23 ms 4956 KB Output is correct
27 Execution timed out 1050 ms 5464 KB Time limit exceeded
28 Halted 0 ms 0 KB -