답안 #1075976

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1075976 2024-08-26T10:09:48 Z MarwenElarbi 봉쇄 시간 (IOI23_closing) C++17
0 / 100
1000 ms 30004 KB
#include <bits/stdc++.h>
#include "closing.h"
using namespace std;
#define pb push_back
#define fi first
#define se second
const int nax = 2e5+5;
const int MOD = 1e9+7;
vector<pair<int,int>> adj[nax];
int max_score(int N, int X, int Y, long long K,
              std::vector<int> U, std::vector<int> V, std::vector<int> W)
{
    vector<pair<int,int>> adj[N];
    long long a[N],b[N];
    if(X>Y) swap(X,Y);
    for (int i = 0; i < N-1; ++i)
    {
        adj[U[i]].pb({V[i],W[i]});
        adj[V[i]].pb({U[i],W[i]});
    }
    for (int i = 0; i < N; ++i)
    {
        if(adj[i].size()==1) continue;
        if(adj[i][0].fi>adj[i][1].fi) swap(adj[i][0],adj[i][1]);
    }
    a[X]=0;
    b[Y]=0;
    for (int i = X+1; i < N; ++i) a[i]=a[i-1]+adj[i][0].se;
    for (int i = X-1; i >=0; --i) a[i]=a[i+1]+(i ? adj[i][1].se : adj[i][0].se);
    for (int i = Y+1; i < N; ++i) b[i]=b[i-1]+adj[i][0].se;
    for (int i = Y-1; i >=0; --i) b[i]=b[i+1]+(i ? adj[i][1].se : adj[i][0].se);
    long long pre[N];
    memset(pre,0,sizeof pre);
    pre[Y]=0;
    for (int i = Y+1; i < N; ++i) pre[i]=pre[i-1]+b[i];
    long long cnt=K;
    long long ans=0;
    int res=0;
    for (int i = X; i >= 0; i--)
    {
        ans++;
        cnt-=a[i];
        if(cnt<0) break;
        long long cntj=cnt;
        int ansj=ans;
        for (int j = X; j < N; ++j)
        {
            if(j>X) ansj++;
            cntj-=a[j];
            if(cntj<0) break;
            long long cntk=cntj;
            int ansk=ansj;
            for (int k = Y; k >= 0; k--)
            {
                ansk++;
                if(k>j) cntk-=b[k];
                else if(b[k]>a[j]) cntk-=(b[k]-a[j]);
                if(cntk<0) break;
                int left=max(j,Y);
                int l=left;
                int r=N;
                while(r-l>1){
                    int mid=(r+l)/2;
                    if(pre[mid]-pre[left-1]>cntk) r=mid;
                    else l=mid;
                }
                res=max(res,ansk+(l-left));
            }
        }
    }
    return res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1085 ms 30004 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4956 KB 1st lines differ - on the 1st token, expected: '3', found: '4'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4956 KB 1st lines differ - on the 1st token, expected: '3', found: '4'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4956 KB 1st lines differ - on the 1st token, expected: '3', found: '4'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5212 KB Output is correct
2 Incorrect 2 ms 4956 KB 1st lines differ - on the 1st token, expected: '3', found: '4'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5212 KB Output is correct
2 Incorrect 2 ms 4956 KB 1st lines differ - on the 1st token, expected: '3', found: '4'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5212 KB Output is correct
2 Incorrect 2 ms 4956 KB 1st lines differ - on the 1st token, expected: '3', found: '4'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5212 KB Output is correct
2 Incorrect 2 ms 4956 KB 1st lines differ - on the 1st token, expected: '3', found: '4'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5212 KB Output is correct
2 Incorrect 2 ms 4956 KB 1st lines differ - on the 1st token, expected: '3', found: '4'
3 Halted 0 ms 0 KB -