답안 #995910

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
995910 2024-06-10T03:49:27 Z irmuun 봉쇄 시간 (IOI23_closing) C++17
0 / 100
1000 ms 23108 KB
#include<bits/stdc++.h>
#include "closing.h"

using namespace std;

#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()

int max_score(int N,int X,int Y,ll K,vector<int>U,vector<int>V,vector<int>W){
    if(X>Y) swap(X,Y);
    vector<pair<int,int>>adj[N];
    for(int i=0;i<N-1;i++){
        adj[U[i]].pb({V[i],W[i]});
        adj[V[i]].pb({U[i],W[i]});
    }
    ll D[N];
    D[0]=0;
    for(int i=1;i<N;i++){
        for(auto [j,w]:adj[i]){
            if(j==i-1){
                D[i]=D[i-1]+w;
            }
        }
    }
    function <ll(int,int)> calc=[&](int i,int j){
        if(i>j) swap(i,j);
        return D[j]-D[i];
    };
    // check all interval that is reacheble from both
    vector<ll>v;
    int ans=0;
    for(int l=0;l<N;l++){
        for(int r=l;r<N;r++){
            cout<<l<<' '<<r<<"\n";
            if(r<X||l>Y) continue;//not possible
            cout<<l<<' '<<r<<'\n';
            ll total=0;
            int cnt=0;
            for(int i=l;i<=r;i++){
                total+=max(calc(i,X),calc(i,Y));
                cnt+=2;
            }
            for(int i=X;i<l;i++){
                total+=calc(i,X);
                cnt++;
            }
            for(int i=Y;i>=r;i--){
                total+=calc(i,Y);
                cnt++;
            }
            if(total>K){
                continue;
            }
            for(int i=0;i<min(X,l)-1;i++){
                v.pb(calc(X,i));
            }
            for(int i=max(r,Y)+1;i<N;i++){
                v.pb(calc(Y,i));
            }
            sort(all(v));
            for(int i=0;i<v.size();i++){
                if(total+v[i]<=K){
                    total+=v[i];
                    cnt++;
                }
            }
            ans=max(ans,cnt);
            v.clear();
        }
    }
    for(int i=0;i<N;i++){
        v.pb(min(calc(i,X),calc(i,Y)));
    }
    sort(all(v));
    int cnt=0;
    ll total=0;
    for(int i=0;i<N;i++){
        if(total+v[i]<=K){
            total+=v[i];
            cnt++;
        }
    }
    ans=max(ans,cnt);
    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:65:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |             for(int i=0;i<v.size();i++){
      |                         ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Possible tampering with the output
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1102 ms 23108 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Possible tampering with the output
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Possible tampering with the output
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Possible tampering with the output
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Possible tampering with the output
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Possible tampering with the output
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Possible tampering with the output
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Possible tampering with the output
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Possible tampering with the output
2 Halted 0 ms 0 KB -