답안 #980166

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
980166 2024-05-12T00:28:50 Z vjudge1 봉쇄 시간 (IOI23_closing) C++17
29 / 100
307 ms 20280 KB
#include "closing.h"
using namespace std;
#include <bits/stdc++.h>
#define pb push_back

using lli=long long;
#define deb(x) cout<<#x<<": "<<x<<endl;
int  max_score(int N, int X, int Y, long long K,
              vector<int> U, vector<int> V, vector<int> W)
{
   if(N>500){
    vector<vector<pair<lli,lli>>> adj (N);
    for(lli i=0; i<N-1; ++i){
        adj[U[i]].pb({W[i], V[i]});
        adj[V[i]].pb({W[i], U[i]});
    }
    priority_queue<pair<lli,lli>, vector<pair<lli,lli>>, greater<pair<lli,lli>>> pq;
    pq.push({0, X});
    pq.push({0,Y});
    vector<bool> visited (N, false);
    int ans=0;
    while(!pq.empty()){
        lli a=pq.top().first;
        lli b=pq.top().second;
        pq.pop();
        if(visited[b]) continue;
        if(K<a) break;
        visited[b]=true;
        ans++;
        K-=a;
        for(lli i=0; i<adj[b].size(); ++i){
            if(!visited[adj[b][i].second]){
            pq.push({adj[b][i].first+a, adj[b][i].second});
            }
        }
    }
    return ans;
   } 
   int ans=0;
    vector<vector<pair<lli,lli>>> adj (N);
    vector<vector<lli>> mat (N, vector<lli> (N, -1));
    for(lli i=0; i<N-1; ++i){
        adj[U[i]].pb({W[i], V[i]});
        adj[V[i]].pb({W[i], U[i]});
        mat[U[i]][V[i]]=W[i];
        mat[V[i]][U[i]]=W[i];
    }

    int ini=0;
    int ant=0;
    while(adj[ini].size()!=1){
        if(adj[ini][0].second!=ant){
            ant=ini;
            ini=adj[ini][0].second;
        }
        else{
            ant=ini;
            ini=adj[ini][1].second;
        }
    }
    int last=adj[ini][0].second;
    ant=ini;
    while(adj[last].size()!=1){
        if(adj[last][0].second!=ant){
            ant=last;
            last=adj[last][0].second;
        }
        else{
            ant=last;
            last=adj[last][1].second;
        }
    }
    
    vector<int> ord;
    ord.pb(ini);
    int rec=adj[ini][0].second;
    while(rec!=last){
        ord.pb(rec);
        if(adj[rec][0].second!=ord[ord.size()-2]){
            rec=adj[rec][0].second;
        }
        else{
            rec=adj[rec][1].second;
        }
    }
    ord.pb(rec);
    vector<int> pos (N);
    for(int i=0; i<N; ++i){
        pos[ord[i]]=i;
    }


    for(int i=pos[X]; i>=0; --i){
        vector<int> values(N,0);
        lli cant=K;
        for(lli a=pos[X]-1; a>=i; --a){
            values[a]=values[a+1]+mat[ord[a]][ord[a+1]];
            cant-=values[a];
        }
        lli help=cant;
        
        if(cant<0) break;
        for(lli j=pos[X]; j<N; ++j){
            cant=help;
         
            if(j!=pos[X]){
                values[j]=values[j-1]+mat[ord[j]][ord[j-1]];
                help-=values[j];
                cant-=values[j];
            
            }
            if(cant<0) break;
            priority_queue<pair<pair<lli,lli>, lli>, vector<pair<pair<lli,lli>, lli>>, greater<pair<pair<lli,lli>, lli>>> pq;
            pq.push({{0,0}, pos[Y]});
            int aux=j-i+1;
            vector<bool> visited(N, false);
            while(!pq.empty()){
                lli a=pq.top().first.first;
                lli b=pq.top().first.second;
                lli c=pq.top().second;
                pq.pop();
                if(visited[c]) continue;
                visited[c]=true;
         
                if(cant<a) break;
                aux++;
                cant-=a;
                if(c+1<N && !visited[c+1]){
                    pq.push({{max(b+mat[ord[c]][ord[c+1]]-values[c+1],0ll), b+mat[ord[c]][ord[c+1]]}, c+1});
                }
                if(c-1>=0 && !visited[c-1]){
                     pq.push({{max(b+mat[ord[c]][ord[c-1]]-values[c-1],0ll), b+mat[ord[c]][ord[c-1]]}, c-1});
                }

            }
        
            ans=max(ans,aux );
      
        }

    }



   return ans;

}

Compilation message

closing.cpp: In function 'int max_score(int, int, int, long long int, std::vector<int>, std::vector<int>, std::vector<int>)':
closing.cpp:31:23: warning: comparison of integer expressions of different signedness: 'lli' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |         for(lli i=0; i<adj[b].size(); ++i){
      |                      ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 20188 KB Output is correct
2 Correct 76 ms 20280 KB Output is correct
3 Correct 54 ms 2904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 376 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 376 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 3 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 264 ms 2396 KB Output is correct
20 Correct 1 ms 1884 KB Output is correct
21 Correct 307 ms 2388 KB Output is correct
22 Correct 1 ms 2552 KB Output is correct
23 Correct 3 ms 2396 KB Output is correct
24 Correct 3 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 376 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 3 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 264 ms 2396 KB Output is correct
20 Correct 1 ms 1884 KB Output is correct
21 Correct 307 ms 2388 KB Output is correct
22 Correct 1 ms 2552 KB Output is correct
23 Correct 3 ms 2396 KB Output is correct
24 Correct 3 ms 2396 KB Output is correct
25 Correct 24 ms 344 KB Output is correct
26 Incorrect 1 ms 604 KB 1st lines differ - on the 1st token, expected: '5595', found: '2802'
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 376 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Incorrect 1 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '8'
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 376 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 3 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Incorrect 1 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '8'
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 376 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 3 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 264 ms 2396 KB Output is correct
21 Correct 1 ms 1884 KB Output is correct
22 Correct 307 ms 2388 KB Output is correct
23 Correct 1 ms 2552 KB Output is correct
24 Correct 3 ms 2396 KB Output is correct
25 Correct 3 ms 2396 KB Output is correct
26 Incorrect 1 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '8'
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 376 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 3 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 264 ms 2396 KB Output is correct
21 Correct 1 ms 1884 KB Output is correct
22 Correct 307 ms 2388 KB Output is correct
23 Correct 1 ms 2552 KB Output is correct
24 Correct 3 ms 2396 KB Output is correct
25 Correct 3 ms 2396 KB Output is correct
26 Correct 24 ms 344 KB Output is correct
27 Incorrect 1 ms 604 KB 1st lines differ - on the 1st token, expected: '5595', found: '2802'
28 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 376 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 3 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 264 ms 2396 KB Output is correct
21 Correct 1 ms 1884 KB Output is correct
22 Correct 307 ms 2388 KB Output is correct
23 Correct 1 ms 2552 KB Output is correct
24 Correct 3 ms 2396 KB Output is correct
25 Correct 3 ms 2396 KB Output is correct
26 Correct 24 ms 344 KB Output is correct
27 Incorrect 1 ms 604 KB 1st lines differ - on the 1st token, expected: '5595', found: '2802'
28 Halted 0 ms 0 KB -