Submission #960406

# Submission time Handle Problem Language Result Execution time Memory
960406 2024-04-10T11:58:12 Z Prieved1 Closing Time (IOI23_closing) C++17
0 / 100
1000 ms 1159044 KB
#include "closing.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN=200010;
vector<pair<int,int>> g[MAXN];
long long distX[MAXN], distY[MAXN];
int dd[MAXN];
vector<int> path;
void dfsx(int at, int p) {
  for(auto [to,w]:g[at]) {
    if(to==p)continue;
    distX[to]=distX[at]+w;
    dfsx(to, at);
  }
}
void dfsy(int at, int p) {
  for(auto [to,w]:g[at]) {
    if(to==p)continue;
    distY[to]=distY[at]+w;
    dfsy(to, at);
    dd[at]|=dd[to];
  }
  if(dd[at])path.push_back(at);
}
int max_score(int N, int X, int Y, long long K,
              std::vector<int> U, std::vector<int> V, std::vector<int> W)
{
  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]});
  }
  dd[X]=1;
  dfsx(X, -1);
  dfsy(Y, -1);
  int ans=0;
  // case 1
  {
    int cnt=0;
    priority_queue<long long> pq;
    for(int i = 0;i<N;i++) {
      pq.push(-distX[i]);
      pq.push(-distY[i]);
    }
    long long sum=0;
    while(sum<=K and pq.size()) {
      sum-=pq.top();
      cnt++;
      pq.pop();
      if(sum<=K)ans=max(ans,cnt);
    }
  }
  // case 2
  {
    for(int i = 0;i<N;i++) {
      if(distX[i]>distY[i])swap(distX[i], distY[i]);
    }
    int upd[N];
    memset(upd, 0, sizeof upd);
    for(int i:path) {
      upd[i]++;
    }
    long long dp[N+1][N+1];
    for(int i = 0;i<=N;i++)
      for(int j = 0;j<=N;j++)
        dp[i][j]=1e18;
    dp[0][0]=0;
    for(int i = 1;i<=N;i++) {
      if(upd[i-1]==0) {
        for(int j = 0;j<=N;j++){
          dp[i][j]=dp[i-1][j];
        }
      }
      for(int j = 1;j<=N;j++) {
        dp[i][j]=min(dp[i][j], dp[i-1][j-1]+distX[i-1]);
      }
      for(int j = 2;j<=N;j++) {
        dp[i][j]=min(dp[i][j], dp[i-1][j-2]+distY[i-1]);
      }
    }
    for(int j = 0;j<=N;j++) {
      if(dp[N][j]<=K)ans=max(ans,j);
    }
  }
  for(int i = 0;i<=N;i++) {
    dd[i]=0;
    distX[i]=distY[i]=0;
    g[i].clear();
  }
  path.clear();
  return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1090 ms 1159044 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6744 KB Output is correct
2 Incorrect 2 ms 6748 KB 1st lines differ - on the 1st token, expected: '30', found: '24'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6744 KB Output is correct
2 Incorrect 2 ms 6748 KB 1st lines differ - on the 1st token, expected: '30', found: '24'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6744 KB Output is correct
2 Incorrect 2 ms 6748 KB 1st lines differ - on the 1st token, expected: '30', found: '24'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6748 KB Output is correct
2 Correct 2 ms 6744 KB Output is correct
3 Incorrect 2 ms 6748 KB 1st lines differ - on the 1st token, expected: '30', found: '24'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6748 KB Output is correct
2 Correct 2 ms 6744 KB Output is correct
3 Incorrect 2 ms 6748 KB 1st lines differ - on the 1st token, expected: '30', found: '24'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6748 KB Output is correct
2 Correct 2 ms 6744 KB Output is correct
3 Incorrect 2 ms 6748 KB 1st lines differ - on the 1st token, expected: '30', found: '24'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6748 KB Output is correct
2 Correct 2 ms 6744 KB Output is correct
3 Incorrect 2 ms 6748 KB 1st lines differ - on the 1st token, expected: '30', found: '24'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6748 KB Output is correct
2 Correct 2 ms 6744 KB Output is correct
3 Incorrect 2 ms 6748 KB 1st lines differ - on the 1st token, expected: '30', found: '24'
4 Halted 0 ms 0 KB -