Submission #1075553

# Submission time Handle Problem Language Result Execution time Memory
1075553 2024-08-26T07:40:29 Z c2zi6 Closing Time (IOI23_closing) C++17
43 / 100
149 ms 41808 KB
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include "closing.h"
 
namespace GREEDY {
    int n;
    VVPI gp;
    void dfs(VL& dist, int u, int p = -1) {
        for (auto[v, w] : gp[u]) if (v != p) {
            dist[v] = dist[u] + w;
            dfs(dist, v, u);
        }
    }
    VL distx, disty;
    int max_score(int N, int X, int Y, ll K, VI U, VI V, VI W) {
        n = N;
        gp = VVPI(n);
        rep(i, n-1) {
            auto[u, v, w] = make_tuple(U[i], V[i], W[i]);
            gp[u].pb({v, w});
            gp[v].pb({u, w});
        }
        distx = disty = VL(n);
        dfs(distx, X);
        dfs(disty, Y);
        VL a;
        for (ll x : distx) a.pb(x);
        for (ll x : disty) a.pb(x);
        sort(all(a));
        a.pb(2e18);
        int ans = 0;
        for (ll x : a) {
            if (x <= K) {
                K -= x;
                ans++;
            } else break;
        }
        return ans;
    }
};
 
namespace LINEAR {
    int max_score(int N, int X, int Y, ll K, VI U, VI V, VI W) {
        int greedyans = GREEDY::max_score(N, X, Y, K, U, V, W);
        int n = N;
        VI a = W;
        if (Y < X) swap(X, Y);
        VL distx = GREEDY::distx;
        VL disty = GREEDY::disty;
        int ans = 0;
        priority_queue<PLL> pq;
        rep(i, n) {
            if (i < X) pq.push({-distx[i], -(disty[i]-distx[i])});
            else if (i > Y) pq.push({-disty[i], -(distx[i]-disty[i])});
            else {
                ll mx = max(distx[i], disty[i]);
                ll mn = min(distx[i], disty[i]);
                pq.push({-(mx-mn), +1});
                K -= mn;
                ans++;
                if (K < 0) return greedyans;
            }
        }
        while (pq.size()) {
            auto[cost, nxt] = pq.top();
            pq.pop();
            K += cost;
            if (K < 0) break;
            ans++;
            if (nxt != +1) pq.push({nxt, +1});
        }
        return max(greedyans, ans);
    }
};
 
int max_score(int N, int X, int Y, ll K, VI U, VI V, VI W) {
    return LINEAR::max_score(N, X, Y, K, U, V, W);
    return GREEDY::max_score(N, X, Y, K, U, V, W);
}
 
 
 
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 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 Correct 149 ms 36544 KB Output is correct
2 Correct 120 ms 41808 KB Output is correct
3 Correct 72 ms 5144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 600 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 600 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 2 ms 348 KB Output is correct
26 Correct 2 ms 860 KB Output is correct
27 Correct 1 ms 860 KB Output is correct
28 Correct 2 ms 860 KB Output is correct
29 Correct 3 ms 960 KB Output is correct
30 Correct 2 ms 860 KB Output is correct
31 Correct 3 ms 1116 KB Output is correct
32 Correct 2 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 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 1 ms 344 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 1 ms 344 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 1 ms 344 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 1 ms 344 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -