답안 #913795

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
913795 2024-01-20T09:09:19 Z abcvuitunggio 봉쇄 시간 (IOI23_closing) C++17
17 / 100
482 ms 51744 KB
#include "closing.h"
#include <bits/stdc++.h>
using namespace std;
vector <pair <int, int>> ke[200001];
long long d[200001][2],cur;
int p[200001],ch[200001],vis[200001];
set <pair <long long, int>> s,s2;
void dfs(int u, int i, int par=-1){
    for (auto [v,w]:ke[u])
        if (v!=par){
            d[v][i]=d[u][i]+w;
            p[v]=u;
            dfs(v,i,u);
        }
}
int max_score(int N, int X, int Y, long long K, vector<int> U, vector<int> V, vector<int> W){
    for (int i=0;i<N-1;i++){
        ke[U[i]].push_back({V[i],W[i]});
        ke[V[i]].push_back({U[i],W[i]});
    }
    memset(ch,0,sizeof(ch));
    d[X][0]=d[Y][1]=0;
    dfs(X,0);
    dfs(Y,1);
    for (;X!=Y;X=p[X])
        ch[X]=1;
    ch[Y]=1;
    int res=0,cnt=0;
    for (int i=0;i<N;i++)
        s.insert({min(d[i][0],d[i][1]),i});
    cur=0;
    while (!s.empty()&&cur+(*s.begin()).first<=K){
        cur+=(*s.begin()).first;
        res++;
        s.erase(s.begin());
    }
    s.clear();
    cur=0;
    for (int i=0;i<N;i++){
        if (ch[i]){
            s.insert({abs(d[i][0]-d[i][1]),i});
            cur+=min(d[i][0],d[i][1]);
            cnt++;
        }
        else{
            s.insert({min(d[i][0],d[i][1]),i});
            s2.insert({max(d[i][0],d[i][1]),i});
        }
    }
    while (!s.empty()&&!s2.empty()){
        auto [c,u]=*s.begin();
        s.erase(s.begin());
        auto [c2,u2]=*s2.begin();
        s2.erase(s2.begin());
        int x=0,i=0,y=0;
        if (s.empty()){
            s.insert({c,u});
            x=c2;
            i=u2;
            y=2;
        }
        else{
            if (c+(*s.begin()).first<c2){
                s2.insert({c2,u2});
                x=c;
                i=u;
                y=1;
            }
            else{
                s.insert({c,u});
                x=c2;
                i=u2;
                y=2;
            }
        }
        if (cur+x>K)
            break;
        cur+=x;
        cnt+=y;
        if (y==1&&!vis[i]&&!ch[i]){
            s.insert({abs(d[i][0]-d[i][1]),i});
            s2.erase(s2.find({max(d[i][0],d[i][1]),i}));
        }
        if (y==2&&!vis[i])
            s.erase(s.find({min(d[i][0],d[i][1]),i}));
        vis[i]=1;
    }
    while (!s.empty()&&cur+(*s.begin()).first<=K){
        cur+=(*s.begin()).first;
        cnt++;
        s.erase(s.begin());
    }
    while (!s2.empty()&&cur+(*s2.begin()).first<=K){
        cur+=(*s2.begin()).first;
        cnt+=2;
        s2.erase(s2.begin());
    }
    s.clear();
    s2.clear();
    for (int i=0;i<N;i++)
        ke[i].clear();
    return max(res,(cur>K?0:cnt));
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 10328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 482 ms 50956 KB Output is correct
2 Correct 401 ms 51744 KB Output is correct
3 Correct 122 ms 14908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 10588 KB Output is correct
2 Correct 4 ms 10332 KB Output is correct
3 Correct 4 ms 10588 KB Output is correct
4 Correct 4 ms 10328 KB Output is correct
5 Correct 4 ms 10444 KB Output is correct
6 Correct 3 ms 10432 KB Output is correct
7 Correct 3 ms 10332 KB Output is correct
8 Correct 3 ms 10328 KB Output is correct
9 Correct 3 ms 10436 KB Output is correct
10 Correct 3 ms 10332 KB Output is correct
11 Correct 4 ms 10436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 10588 KB Output is correct
2 Correct 4 ms 10332 KB Output is correct
3 Correct 4 ms 10588 KB Output is correct
4 Correct 4 ms 10328 KB Output is correct
5 Correct 4 ms 10444 KB Output is correct
6 Correct 3 ms 10432 KB Output is correct
7 Correct 3 ms 10332 KB Output is correct
8 Correct 3 ms 10328 KB Output is correct
9 Correct 3 ms 10436 KB Output is correct
10 Correct 3 ms 10332 KB Output is correct
11 Correct 4 ms 10436 KB Output is correct
12 Correct 4 ms 10488 KB Output is correct
13 Correct 3 ms 10332 KB Output is correct
14 Correct 3 ms 10332 KB Output is correct
15 Correct 3 ms 10332 KB Output is correct
16 Correct 3 ms 10328 KB Output is correct
17 Correct 4 ms 10332 KB Output is correct
18 Incorrect 4 ms 10456 KB 2nd lines differ - on the 1st token, expected: '25', found: '27'
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 10588 KB Output is correct
2 Correct 4 ms 10332 KB Output is correct
3 Correct 4 ms 10588 KB Output is correct
4 Correct 4 ms 10328 KB Output is correct
5 Correct 4 ms 10444 KB Output is correct
6 Correct 3 ms 10432 KB Output is correct
7 Correct 3 ms 10332 KB Output is correct
8 Correct 3 ms 10328 KB Output is correct
9 Correct 3 ms 10436 KB Output is correct
10 Correct 3 ms 10332 KB Output is correct
11 Correct 4 ms 10436 KB Output is correct
12 Correct 4 ms 10488 KB Output is correct
13 Correct 3 ms 10332 KB Output is correct
14 Correct 3 ms 10332 KB Output is correct
15 Correct 3 ms 10332 KB Output is correct
16 Correct 3 ms 10328 KB Output is correct
17 Correct 4 ms 10332 KB Output is correct
18 Incorrect 4 ms 10456 KB 2nd lines differ - on the 1st token, expected: '25', found: '27'
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 10328 KB Output is correct
2 Correct 4 ms 10588 KB Output is correct
3 Correct 4 ms 10332 KB Output is correct
4 Correct 4 ms 10588 KB Output is correct
5 Correct 4 ms 10328 KB Output is correct
6 Correct 4 ms 10444 KB Output is correct
7 Correct 4 ms 10328 KB Output is correct
8 Correct 3 ms 10332 KB Output is correct
9 Correct 4 ms 10332 KB Output is correct
10 Correct 4 ms 10332 KB Output is correct
11 Correct 4 ms 10332 KB Output is correct
12 Correct 3 ms 10332 KB Output is correct
13 Correct 3 ms 10332 KB Output is correct
14 Correct 4 ms 10328 KB Output is correct
15 Correct 4 ms 10584 KB Output is correct
16 Correct 3 ms 10332 KB Output is correct
17 Correct 3 ms 10332 KB Output is correct
18 Correct 3 ms 10328 KB Output is correct
19 Correct 4 ms 10328 KB Output is correct
20 Correct 3 ms 10332 KB Output is correct
21 Correct 4 ms 10328 KB Output is correct
22 Correct 3 ms 10328 KB Output is correct
23 Correct 3 ms 10688 KB Output is correct
24 Incorrect 3 ms 10332 KB 1st lines differ - on the 1st token, expected: '10', found: '9'
25 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 10328 KB Output is correct
2 Correct 4 ms 10588 KB Output is correct
3 Correct 4 ms 10332 KB Output is correct
4 Correct 4 ms 10588 KB Output is correct
5 Correct 4 ms 10328 KB Output is correct
6 Correct 4 ms 10444 KB Output is correct
7 Correct 3 ms 10432 KB Output is correct
8 Correct 3 ms 10332 KB Output is correct
9 Correct 3 ms 10328 KB Output is correct
10 Correct 3 ms 10436 KB Output is correct
11 Correct 3 ms 10332 KB Output is correct
12 Correct 4 ms 10436 KB Output is correct
13 Correct 4 ms 10488 KB Output is correct
14 Correct 3 ms 10332 KB Output is correct
15 Correct 3 ms 10332 KB Output is correct
16 Correct 3 ms 10332 KB Output is correct
17 Correct 3 ms 10328 KB Output is correct
18 Correct 4 ms 10332 KB Output is correct
19 Correct 4 ms 10328 KB Output is correct
20 Correct 3 ms 10332 KB Output is correct
21 Correct 4 ms 10332 KB Output is correct
22 Correct 4 ms 10332 KB Output is correct
23 Correct 4 ms 10332 KB Output is correct
24 Correct 3 ms 10332 KB Output is correct
25 Correct 3 ms 10332 KB Output is correct
26 Correct 4 ms 10328 KB Output is correct
27 Correct 4 ms 10584 KB Output is correct
28 Correct 3 ms 10332 KB Output is correct
29 Correct 3 ms 10332 KB Output is correct
30 Correct 3 ms 10328 KB Output is correct
31 Correct 4 ms 10328 KB Output is correct
32 Correct 3 ms 10332 KB Output is correct
33 Correct 4 ms 10328 KB Output is correct
34 Correct 3 ms 10328 KB Output is correct
35 Correct 3 ms 10688 KB Output is correct
36 Incorrect 3 ms 10332 KB 1st lines differ - on the 1st token, expected: '10', found: '9'
37 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 10328 KB Output is correct
2 Correct 4 ms 10588 KB Output is correct
3 Correct 4 ms 10332 KB Output is correct
4 Correct 4 ms 10588 KB Output is correct
5 Correct 4 ms 10328 KB Output is correct
6 Correct 4 ms 10444 KB Output is correct
7 Correct 3 ms 10432 KB Output is correct
8 Correct 3 ms 10332 KB Output is correct
9 Correct 3 ms 10328 KB Output is correct
10 Correct 3 ms 10436 KB Output is correct
11 Correct 3 ms 10332 KB Output is correct
12 Correct 4 ms 10436 KB Output is correct
13 Correct 4 ms 10488 KB Output is correct
14 Correct 3 ms 10332 KB Output is correct
15 Correct 3 ms 10332 KB Output is correct
16 Correct 3 ms 10332 KB Output is correct
17 Correct 3 ms 10328 KB Output is correct
18 Correct 4 ms 10332 KB Output is correct
19 Incorrect 4 ms 10456 KB 2nd lines differ - on the 1st token, expected: '25', found: '27'
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 10328 KB Output is correct
2 Correct 4 ms 10588 KB Output is correct
3 Correct 4 ms 10332 KB Output is correct
4 Correct 4 ms 10588 KB Output is correct
5 Correct 4 ms 10328 KB Output is correct
6 Correct 4 ms 10444 KB Output is correct
7 Correct 3 ms 10432 KB Output is correct
8 Correct 3 ms 10332 KB Output is correct
9 Correct 3 ms 10328 KB Output is correct
10 Correct 3 ms 10436 KB Output is correct
11 Correct 3 ms 10332 KB Output is correct
12 Correct 4 ms 10436 KB Output is correct
13 Correct 4 ms 10488 KB Output is correct
14 Correct 3 ms 10332 KB Output is correct
15 Correct 3 ms 10332 KB Output is correct
16 Correct 3 ms 10332 KB Output is correct
17 Correct 3 ms 10328 KB Output is correct
18 Correct 4 ms 10332 KB Output is correct
19 Incorrect 4 ms 10456 KB 2nd lines differ - on the 1st token, expected: '25', found: '27'
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 10328 KB Output is correct
2 Correct 4 ms 10588 KB Output is correct
3 Correct 4 ms 10332 KB Output is correct
4 Correct 4 ms 10588 KB Output is correct
5 Correct 4 ms 10328 KB Output is correct
6 Correct 4 ms 10444 KB Output is correct
7 Correct 3 ms 10432 KB Output is correct
8 Correct 3 ms 10332 KB Output is correct
9 Correct 3 ms 10328 KB Output is correct
10 Correct 3 ms 10436 KB Output is correct
11 Correct 3 ms 10332 KB Output is correct
12 Correct 4 ms 10436 KB Output is correct
13 Correct 4 ms 10488 KB Output is correct
14 Correct 3 ms 10332 KB Output is correct
15 Correct 3 ms 10332 KB Output is correct
16 Correct 3 ms 10332 KB Output is correct
17 Correct 3 ms 10328 KB Output is correct
18 Correct 4 ms 10332 KB Output is correct
19 Incorrect 4 ms 10456 KB 2nd lines differ - on the 1st token, expected: '25', found: '27'
20 Halted 0 ms 0 KB -