Submission #960422

# Submission time Handle Problem Language Result Execution time Memory
960422 2024-04-10T12:33:50 Z Prieved1 Closing Time (IOI23_closing) C++17
9 / 100
1000 ms 37292 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
  if(N<=1000){
    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]++;
    }
    vector<vector<long long>> dp(N+1, vector<long long> (2*N+1));
    for(int i = 0;i<=N;i++)
      for(int j = 0;j<=2*N;j++)
        dp[i][j]=1e18;
    dp[0][0]=0;
    for(int i = 1;i<=N;i++) {
      if(upd[i]==0) { 
        for(int j = 0;j<=2*N;j++){
          dp[i][j]=dp[i-1][j];
        }
      }
      for(int j = 1;j<=2*N;j++) {
        dp[i][j]=min(dp[i][j], dp[i-1][j-1]+distX[i-1]);
      }
      for(int j = 2;j<=2*N;j++) {
        dp[i][j]=min(dp[i][j], dp[i-1][j-2]+distY[i-1]);
      }
    }
    for(int j = 0;j<=2*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 Correct 100 ms 31956 KB Output is correct
2 Correct 106 ms 37292 KB Output is correct
3 Execution timed out 1074 ms 25400 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6748 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 1 ms 6748 KB Output is correct
7 Correct 2 ms 6748 KB Output is correct
8 Correct 2 ms 6948 KB Output is correct
9 Correct 2 ms 6748 KB Output is correct
10 Correct 2 ms 6744 KB Output is correct
11 Correct 2 ms 6744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6748 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 1 ms 6748 KB Output is correct
7 Correct 2 ms 6748 KB Output is correct
8 Correct 2 ms 6948 KB Output is correct
9 Correct 2 ms 6748 KB Output is correct
10 Correct 2 ms 6744 KB Output is correct
11 Correct 2 ms 6744 KB Output is correct
12 Correct 2 ms 7004 KB Output is correct
13 Correct 2 ms 6972 KB Output is correct
14 Correct 2 ms 6744 KB Output is correct
15 Correct 2 ms 6748 KB Output is correct
16 Correct 2 ms 7004 KB Output is correct
17 Correct 2 ms 7004 KB Output is correct
18 Incorrect 2 ms 6748 KB 2nd lines differ - on the 1st token, expected: '25', found: '24'
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6748 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 1 ms 6748 KB Output is correct
7 Correct 2 ms 6748 KB Output is correct
8 Correct 2 ms 6948 KB Output is correct
9 Correct 2 ms 6748 KB Output is correct
10 Correct 2 ms 6744 KB Output is correct
11 Correct 2 ms 6744 KB Output is correct
12 Correct 2 ms 7004 KB Output is correct
13 Correct 2 ms 6972 KB Output is correct
14 Correct 2 ms 6744 KB Output is correct
15 Correct 2 ms 6748 KB Output is correct
16 Correct 2 ms 7004 KB Output is correct
17 Correct 2 ms 7004 KB Output is correct
18 Incorrect 2 ms 6748 KB 2nd lines differ - on the 1st token, expected: '25', found: '24'
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6748 KB Output is correct
2 Correct 2 ms 6748 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 1 ms 6748 KB Output is correct
7 Correct 2 ms 6748 KB Output is correct
8 Incorrect 2 ms 6748 KB 1st lines differ - on the 1st token, expected: '5', found: '4'
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6748 KB Output is correct
2 Correct 2 ms 6748 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 1 ms 6748 KB Output is correct
7 Correct 1 ms 6748 KB Output is correct
8 Correct 2 ms 6748 KB Output is correct
9 Correct 2 ms 6948 KB Output is correct
10 Correct 2 ms 6748 KB Output is correct
11 Correct 2 ms 6744 KB Output is correct
12 Correct 2 ms 6744 KB Output is correct
13 Correct 2 ms 7004 KB Output is correct
14 Correct 2 ms 6972 KB Output is correct
15 Correct 2 ms 6744 KB Output is correct
16 Correct 2 ms 6748 KB Output is correct
17 Correct 2 ms 7004 KB Output is correct
18 Correct 2 ms 7004 KB Output is correct
19 Correct 2 ms 6748 KB Output is correct
20 Incorrect 2 ms 6748 KB 1st lines differ - on the 1st token, expected: '5', found: '4'
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6748 KB Output is correct
2 Correct 2 ms 6748 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 1 ms 6748 KB Output is correct
7 Correct 1 ms 6748 KB Output is correct
8 Correct 2 ms 6748 KB Output is correct
9 Correct 2 ms 6948 KB Output is correct
10 Correct 2 ms 6748 KB Output is correct
11 Correct 2 ms 6744 KB Output is correct
12 Correct 2 ms 6744 KB Output is correct
13 Correct 2 ms 7004 KB Output is correct
14 Correct 2 ms 6972 KB Output is correct
15 Correct 2 ms 6744 KB Output is correct
16 Correct 2 ms 6748 KB Output is correct
17 Correct 2 ms 7004 KB Output is correct
18 Correct 2 ms 7004 KB Output is correct
19 Incorrect 2 ms 6748 KB 2nd lines differ - on the 1st token, expected: '25', found: '24'
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6748 KB Output is correct
2 Correct 2 ms 6748 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 1 ms 6748 KB Output is correct
7 Correct 1 ms 6748 KB Output is correct
8 Correct 2 ms 6748 KB Output is correct
9 Correct 2 ms 6948 KB Output is correct
10 Correct 2 ms 6748 KB Output is correct
11 Correct 2 ms 6744 KB Output is correct
12 Correct 2 ms 6744 KB Output is correct
13 Correct 2 ms 7004 KB Output is correct
14 Correct 2 ms 6972 KB Output is correct
15 Correct 2 ms 6744 KB Output is correct
16 Correct 2 ms 6748 KB Output is correct
17 Correct 2 ms 7004 KB Output is correct
18 Correct 2 ms 7004 KB Output is correct
19 Incorrect 2 ms 6748 KB 2nd lines differ - on the 1st token, expected: '25', found: '24'
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6748 KB Output is correct
2 Correct 2 ms 6748 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 1 ms 6748 KB Output is correct
7 Correct 1 ms 6748 KB Output is correct
8 Correct 2 ms 6748 KB Output is correct
9 Correct 2 ms 6948 KB Output is correct
10 Correct 2 ms 6748 KB Output is correct
11 Correct 2 ms 6744 KB Output is correct
12 Correct 2 ms 6744 KB Output is correct
13 Correct 2 ms 7004 KB Output is correct
14 Correct 2 ms 6972 KB Output is correct
15 Correct 2 ms 6744 KB Output is correct
16 Correct 2 ms 6748 KB Output is correct
17 Correct 2 ms 7004 KB Output is correct
18 Correct 2 ms 7004 KB Output is correct
19 Incorrect 2 ms 6748 KB 2nd lines differ - on the 1st token, expected: '25', found: '24'
20 Halted 0 ms 0 KB -