Submission #1027959

# Submission time Handle Problem Language Result Execution time Memory
1027959 2024-07-19T11:59:54 Z Mr_Husanboy Closing Time (IOI23_closing) C++17
0 / 100
1000 ms 27264 KB
#include "closing.h"
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ff first
#define ss second
#define all(a) (a).begin(), (a).end()
const long long infl = 2e18 + 10;

template<typename T>
int len(T &a){return a.size();}



int max_score(int n, int x, int y, long long k,
              vector<int> U, vector<int> V, vector<int> W)
{
    vector<vector<pair<int,int>>> g(n);
    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]});
    }

    vector<ll> dx(n), dy(n);
    auto dfs = [&](auto &dfs, int i, int p = -1)->void{
        for(auto [u, w] : g[i]){
            if(u == p) continue;
            dx[u] = dx[i] + w;
            dfs(dfs, u, i);
        }
    };
    dfs(dfs, x);
    swap(dx, dy);
    dfs(dfs, y);
    swap(dx, dy); 
    // for(int i = 0; i < n;i ++){
    //     cout << dx[i] << ' ' << dy[i] << endl;
    // } 
    int ans = 0;

    for(int l = x; l < n; l ++){
        for(int r = y; r >= 0; r --){
            ll tot = 0;
            for(int j = r; j <= l; j ++){
                tot += max(dx[j], dy[j]);
            }
            for(int j = x; j < min(l + 1, r); j ++) tot += dx[j];
            for(int j = y; j > max(r - 1, l); j --) tot += dy[j];
            // cout << tot << endl;
            if(tot > k){
                break;
            }
            vector<int> one;
            for(int j = 0; j < min(r, x); j ++){
                one.push_back(dx[j]);
            }
            for(int j = max(l, y) + 1; j < n; j ++){
                one.push_back(dy[j]);
            }
            sort(all(one));
            int i = 0;
            while(i < len(one)){
                tot += one[i];
                if(tot > k) break;
                i ++;
            }
            //cout << l << ' ' << r << ' ' << i << endl;
            ans = max(ans, l - x + 1 + y - r + 1 + i);
        }
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1079 ms 27264 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '30', found: '19'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '30', found: '19'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '30', found: '19'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -