Submission #861705

# Submission time Handle Problem Language Result Execution time Memory
861705 2023-10-16T16:55:33 Z faustaadp Closing Time (IOI23_closing) C++17
21 / 100
1000 ms 58336 KB
#include "closing.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#include <vector>
const ll NN = 2e5 + 5;
vector<pll> v[NN];
ll isi[NN], py[NN], te, ps[NN];
vector<ll> isi2;
void dfs(ll pos, ll par, ll now)
{
    te++;
    isi[te] = pos;
    py[pos] = te;
    ps[te] = now;
    for(auto nx : v[pos])
    {
        if(nx.fi != par)
            dfs(nx.fi, pos, now + nx.se);
    }
}
void dfs2(ll pos, ll par, ll now)
{
    isi2.pb(now);
    for(auto nx : v[pos])
    {
        if(nx.fi != par)
            dfs2(nx.fi, pos, now + nx.se);
    }
}
int max_score(int N, int X, int Y, long long K,
              std::vector<int> U, std::vector<int> V, std::vector<int> W)
{
    // cout << X << " " << Y << "_\n";
    ll perlu = (X < Y);
    te = 0;
    ll R = 0;
    for(ll i = 0; i < N; i++)
    {
        py[i] = 0;
        isi[i + 1] = 0;
        v[i].clear();
    }
    isi2.clear();

    for(ll i = 0; i < V.size(); i++)
    {
        // cout << U[i] << " " << V[i] << "    " << W[i] << "@\n";
        v[U[i]].pb(mp(V[i], W[i]));
        v[V[i]].pb(mp(U[i], W[i]));
    }
    for(ll i = 0; i < N; i++)
        if(v[i].size() == 1)
        {
            R = i;
            break;
        }
    dfs(R, R, 0);
    dfs2(X, X, 0);
    dfs2(Y, Y, 0);
    ll now = K, ret = 0;
    sort(isi2.begin(), isi2.end());
    for(ll i = 0; i < 2 * N; i++)
    {
        if(isi2[i] > now)
            break;
        now -= isi2[i];
        ret++;
    }
    // ret = 0;
    // return ret;
    if(py[X] > py[Y])
        swap(X, Y);
    // cout << py[X] << "  " << py[Y] << " @\n";
    for(ll i = py[X]; i <= py[Y]; i++)
    {
        ll sisa = K, now = 0;
        for(ll j = py[X]; j <= i; j++)
        {
            now++;
            sisa -= ps[j] - ps[py[X]];
        }
        for(ll j = i + 1; j <= py[Y]; j++)
        {
            now++;
            sisa -= ps[py[Y]] - ps[j];
        }

        for(ll l = 1; l <= py[X]; l++)
        {   
            vector<ll> cal;
            ll sisa2 = sisa;
            ll now2 = now;
            // cout << now << "@\n";
            for(ll j = l; j < py[X]; j++)
            {
                sisa2 -= ps[py[X]] - ps[j];
                now2++;
                cal.pb(ps[py[Y]] - ps[py[X]]); // Y
            }

            for(ll j = py[X]; j <= i; j++)
                cal.pb(max(0LL, (ps[py[Y]] - ps[j]) - (ps[j] - ps[py[X]])));

            for(ll j = py[Y] + 1; j <= N; j++)
                cal.pb(ps[j] - ps[py[Y]]);

            // cout << i << " " << l << "@\n";
            // cout << cal.size() << " " << now2 << "_\n";
            if(sisa2 < 0)
                continue;

            // cout << i << " " << now << " " << sisa << "_\n";
            sort(cal.begin(), cal.end());
            for(ll j = 0; j < cal.size(); j++)
            {
                if(cal[j] > sisa2)
                    break;
                sisa2 -= cal[j];
                now2++;
            }
            ret = max(ret, now2);
        }
    }

    ll sisa = K;
    now = 0;
    for(ll i = py[X]; i <= py[Y]; i++)
    {
        sisa -= max(ps[py[Y]] - ps[i], ps[i] - ps[py[X]]);
        now += 2;
    }
    // cout << sisa << " " << now << "__\n";
    for(ll l = 1; l <= py[X]; l++)
    {   
        for(ll i = py[Y] + 1; i <= N; i++)
        {
            vector<ll> cal;
            ll sisa2 = sisa;
            ll now2 = now;
            // cout << now << "@\n";
            for(ll j = l; j < py[X]; j++)
            {
                sisa2 -= ps[py[X]] - ps[j];
                now2++;
                cal.pb(ps[py[Y]] - ps[py[X]]); // Y
            }

            for(ll j = py[Y] + 1; j <= i; j++)
            {
                sisa2 -= ps[j] - ps[py[Y]];
                now2++;
                cal.pb(ps[py[Y]] - ps[py[X]]);
            }

            // cout << i << " " << l << "@\n";
            // cout << l << "   " << cal.size() << " " << now2 << "_\n";
            if(sisa2 < 0)
                continue;

            // cout << i << " " << now << " " << sisa << "_\n";
            sort(cal.begin(), cal.end());
            for(ll j = 0; j < cal.size(); j++)
            {
                if(cal[j] > sisa2)
                    break;
                sisa2 -= cal[j];
                now2++;
            }
            ret = max(ret, now2);
        }
    }
    if(perlu)
        return max((int)ret, max_score(N, Y, X, K, U, V, W));
    else
        return ret;
}

Compilation message

closing.cpp: In function 'int max_score(int, int, int, long long int, std::vector<int>, std::vector<int>, std::vector<int>)':
closing.cpp:51:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |     for(ll i = 0; i < V.size(); i++)
      |                   ~~^~~~~~~~~~
closing.cpp:120:29: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  120 |             for(ll j = 0; j < cal.size(); j++)
      |                           ~~^~~~~~~~~~~~
closing.cpp:168:29: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  168 |             for(ll j = 0; j < cal.size(); j++)
      |                           ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1068 ms 34124 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9564 KB Output is correct
2 Correct 2 ms 9564 KB Output is correct
3 Correct 2 ms 9564 KB Output is correct
4 Correct 2 ms 9564 KB Output is correct
5 Correct 2 ms 9564 KB Output is correct
6 Correct 2 ms 9656 KB Output is correct
7 Correct 2 ms 9668 KB Output is correct
8 Correct 2 ms 9812 KB Output is correct
9 Correct 2 ms 9820 KB Output is correct
10 Correct 2 ms 9564 KB Output is correct
11 Correct 2 ms 9564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9564 KB Output is correct
2 Correct 2 ms 9564 KB Output is correct
3 Correct 2 ms 9564 KB Output is correct
4 Correct 2 ms 9564 KB Output is correct
5 Correct 2 ms 9564 KB Output is correct
6 Correct 2 ms 9656 KB Output is correct
7 Correct 2 ms 9668 KB Output is correct
8 Correct 2 ms 9812 KB Output is correct
9 Correct 2 ms 9820 KB Output is correct
10 Correct 2 ms 9564 KB Output is correct
11 Correct 2 ms 9564 KB Output is correct
12 Correct 3 ms 9564 KB Output is correct
13 Correct 2 ms 9564 KB Output is correct
14 Correct 3 ms 9564 KB Output is correct
15 Correct 2 ms 9760 KB Output is correct
16 Correct 2 ms 9564 KB Output is correct
17 Correct 2 ms 9564 KB Output is correct
18 Correct 3 ms 9564 KB Output is correct
19 Correct 154 ms 9728 KB Output is correct
20 Correct 18 ms 9564 KB Output is correct
21 Correct 212 ms 9720 KB Output is correct
22 Correct 6 ms 9560 KB Output is correct
23 Correct 3 ms 9560 KB Output is correct
24 Correct 3 ms 9564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9564 KB Output is correct
2 Correct 2 ms 9564 KB Output is correct
3 Correct 2 ms 9564 KB Output is correct
4 Correct 2 ms 9564 KB Output is correct
5 Correct 2 ms 9564 KB Output is correct
6 Correct 2 ms 9656 KB Output is correct
7 Correct 2 ms 9668 KB Output is correct
8 Correct 2 ms 9812 KB Output is correct
9 Correct 2 ms 9820 KB Output is correct
10 Correct 2 ms 9564 KB Output is correct
11 Correct 2 ms 9564 KB Output is correct
12 Correct 3 ms 9564 KB Output is correct
13 Correct 2 ms 9564 KB Output is correct
14 Correct 3 ms 9564 KB Output is correct
15 Correct 2 ms 9760 KB Output is correct
16 Correct 2 ms 9564 KB Output is correct
17 Correct 2 ms 9564 KB Output is correct
18 Correct 3 ms 9564 KB Output is correct
19 Correct 154 ms 9728 KB Output is correct
20 Correct 18 ms 9564 KB Output is correct
21 Correct 212 ms 9720 KB Output is correct
22 Correct 6 ms 9560 KB Output is correct
23 Correct 3 ms 9560 KB Output is correct
24 Correct 3 ms 9564 KB Output is correct
25 Correct 26 ms 9716 KB Output is correct
26 Execution timed out 1056 ms 10076 KB Time limit exceeded
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9560 KB Output is correct
2 Correct 2 ms 9564 KB Output is correct
3 Correct 2 ms 9564 KB Output is correct
4 Correct 2 ms 9564 KB Output is correct
5 Correct 2 ms 9564 KB Output is correct
6 Correct 2 ms 9564 KB Output is correct
7 Correct 2 ms 9564 KB Output is correct
8 Correct 2 ms 9652 KB Output is correct
9 Correct 2 ms 9564 KB Output is correct
10 Execution timed out 1090 ms 58336 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9560 KB Output is correct
2 Correct 2 ms 9564 KB Output is correct
3 Correct 2 ms 9564 KB Output is correct
4 Correct 2 ms 9564 KB Output is correct
5 Correct 2 ms 9564 KB Output is correct
6 Correct 2 ms 9564 KB Output is correct
7 Correct 2 ms 9656 KB Output is correct
8 Correct 2 ms 9668 KB Output is correct
9 Correct 2 ms 9812 KB Output is correct
10 Correct 2 ms 9820 KB Output is correct
11 Correct 2 ms 9564 KB Output is correct
12 Correct 2 ms 9564 KB Output is correct
13 Correct 3 ms 9564 KB Output is correct
14 Correct 2 ms 9564 KB Output is correct
15 Correct 3 ms 9564 KB Output is correct
16 Correct 2 ms 9760 KB Output is correct
17 Correct 2 ms 9564 KB Output is correct
18 Correct 2 ms 9564 KB Output is correct
19 Correct 2 ms 9564 KB Output is correct
20 Correct 2 ms 9652 KB Output is correct
21 Correct 2 ms 9564 KB Output is correct
22 Execution timed out 1090 ms 58336 KB Time limit exceeded
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9560 KB Output is correct
2 Correct 2 ms 9564 KB Output is correct
3 Correct 2 ms 9564 KB Output is correct
4 Correct 2 ms 9564 KB Output is correct
5 Correct 2 ms 9564 KB Output is correct
6 Correct 2 ms 9564 KB Output is correct
7 Correct 2 ms 9656 KB Output is correct
8 Correct 2 ms 9668 KB Output is correct
9 Correct 2 ms 9812 KB Output is correct
10 Correct 2 ms 9820 KB Output is correct
11 Correct 2 ms 9564 KB Output is correct
12 Correct 2 ms 9564 KB Output is correct
13 Correct 3 ms 9564 KB Output is correct
14 Correct 2 ms 9564 KB Output is correct
15 Correct 3 ms 9564 KB Output is correct
16 Correct 2 ms 9760 KB Output is correct
17 Correct 2 ms 9564 KB Output is correct
18 Correct 2 ms 9564 KB Output is correct
19 Correct 3 ms 9564 KB Output is correct
20 Correct 154 ms 9728 KB Output is correct
21 Correct 18 ms 9564 KB Output is correct
22 Correct 212 ms 9720 KB Output is correct
23 Correct 6 ms 9560 KB Output is correct
24 Correct 3 ms 9560 KB Output is correct
25 Correct 3 ms 9564 KB Output is correct
26 Correct 2 ms 9564 KB Output is correct
27 Correct 2 ms 9652 KB Output is correct
28 Correct 2 ms 9564 KB Output is correct
29 Execution timed out 1090 ms 58336 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9560 KB Output is correct
2 Correct 2 ms 9564 KB Output is correct
3 Correct 2 ms 9564 KB Output is correct
4 Correct 2 ms 9564 KB Output is correct
5 Correct 2 ms 9564 KB Output is correct
6 Correct 2 ms 9564 KB Output is correct
7 Correct 2 ms 9656 KB Output is correct
8 Correct 2 ms 9668 KB Output is correct
9 Correct 2 ms 9812 KB Output is correct
10 Correct 2 ms 9820 KB Output is correct
11 Correct 2 ms 9564 KB Output is correct
12 Correct 2 ms 9564 KB Output is correct
13 Correct 3 ms 9564 KB Output is correct
14 Correct 2 ms 9564 KB Output is correct
15 Correct 3 ms 9564 KB Output is correct
16 Correct 2 ms 9760 KB Output is correct
17 Correct 2 ms 9564 KB Output is correct
18 Correct 2 ms 9564 KB Output is correct
19 Correct 3 ms 9564 KB Output is correct
20 Correct 154 ms 9728 KB Output is correct
21 Correct 18 ms 9564 KB Output is correct
22 Correct 212 ms 9720 KB Output is correct
23 Correct 6 ms 9560 KB Output is correct
24 Correct 3 ms 9560 KB Output is correct
25 Correct 3 ms 9564 KB Output is correct
26 Correct 26 ms 9716 KB Output is correct
27 Execution timed out 1056 ms 10076 KB Time limit exceeded
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9560 KB Output is correct
2 Correct 2 ms 9564 KB Output is correct
3 Correct 2 ms 9564 KB Output is correct
4 Correct 2 ms 9564 KB Output is correct
5 Correct 2 ms 9564 KB Output is correct
6 Correct 2 ms 9564 KB Output is correct
7 Correct 2 ms 9656 KB Output is correct
8 Correct 2 ms 9668 KB Output is correct
9 Correct 2 ms 9812 KB Output is correct
10 Correct 2 ms 9820 KB Output is correct
11 Correct 2 ms 9564 KB Output is correct
12 Correct 2 ms 9564 KB Output is correct
13 Correct 3 ms 9564 KB Output is correct
14 Correct 2 ms 9564 KB Output is correct
15 Correct 3 ms 9564 KB Output is correct
16 Correct 2 ms 9760 KB Output is correct
17 Correct 2 ms 9564 KB Output is correct
18 Correct 2 ms 9564 KB Output is correct
19 Correct 3 ms 9564 KB Output is correct
20 Correct 154 ms 9728 KB Output is correct
21 Correct 18 ms 9564 KB Output is correct
22 Correct 212 ms 9720 KB Output is correct
23 Correct 6 ms 9560 KB Output is correct
24 Correct 3 ms 9560 KB Output is correct
25 Correct 3 ms 9564 KB Output is correct
26 Correct 26 ms 9716 KB Output is correct
27 Execution timed out 1056 ms 10076 KB Time limit exceeded
28 Halted 0 ms 0 KB -