Submission #989141

# Submission time Handle Problem Language Result Execution time Memory
989141 2024-05-27T15:27:47 Z SuPythony Ball Machine (BOI13_ballmachine) C++17
7.53968 / 100
1000 ms 19592 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

vector<vector<int>> al;
vector<int> par;
vector<int> mn;
vector<int> ball;
vector<int> down;
vector<int> order;
set<pair<int,int>> next_node;
int root,n;

void dfs(int u) {
    for (int v: al[u]) {
        dfs(v);
    }
    order[u]=next_node.size()+1;
    next_node.insert({order[u],u});
}

void mndfs(int u) {
    down[u]=-1;
    for (int v: al[u]) {
        mndfs(v);
        if (mn[v]<mn[u]) {
            down[u]=v;
            mn[u]=mn[v];
        }
    }
    mn[u]=min(mn[u],u);
}

int add_ball() {
    auto b=*next_node.begin();
    next_node.erase(next_node.begin());
    ball[b.second]=1;
    return b.second;
}

int main() {
    int q; cin>>n>>q;
    al.assign(n+1,vector<int>());
    par.assign(n+1,-1);
    mn.assign(n+1,1e9);
    ball.assign(n+1,0);
    down.assign(n+1,0);
    order.assign(n+1,0);
    for (int i=1; i<=n; i++) {
        int p; cin>>p;
        if (p==0) {
            root=i;
        } else {
            al[p].push_back(i);
            par[i]=p;
        }
    }
    for (int i=1; i<=n; i++) {
        sort(al[i].begin(),al[i].end());
    }
    dfs(root);
    //mndfs(root);
    while (q--) {
        int t; cin>>t;
        if (t==1) {
            int k; cin>>k;
            int ans;
            for (int i=0; i<k; i++) {
                ans=add_ball();
            }
            cout<<ans<<"\n";
        } else {
            int x; cin>>x;
            ball[x]=0;
            next_node.insert({order[x],x});
            cout<<0<<"\n";
        }
    }
    return 0;
}

Compilation message

ballmachine.cpp: In function 'int main()':
ballmachine.cpp:71:24: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   71 |             cout<<ans<<"\n";
      |                        ^~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 1033 ms 344 KB Time limit exceeded
2 Execution timed out 1025 ms 7504 KB Time limit exceeded
3 Incorrect 170 ms 7760 KB Output isn't correct
4 Execution timed out 1056 ms 348 KB Time limit exceeded
5 Execution timed out 1039 ms 348 KB Time limit exceeded
6 Incorrect 2 ms 348 KB Output isn't correct
7 Execution timed out 1093 ms 348 KB Time limit exceeded
8 Execution timed out 1057 ms 348 KB Time limit exceeded
9 Execution timed out 1042 ms 856 KB Time limit exceeded
10 Execution timed out 1067 ms 2140 KB Time limit exceeded
11 Incorrect 175 ms 7504 KB Output isn't correct
12 Incorrect 157 ms 7760 KB Output isn't correct
13 Incorrect 179 ms 7516 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 111 ms 4176 KB Output is correct
2 Incorrect 188 ms 15184 KB Output isn't correct
3 Incorrect 163 ms 10956 KB Output isn't correct
4 Execution timed out 1057 ms 4948 KB Time limit exceeded
5 Execution timed out 1050 ms 4444 KB Time limit exceeded
6 Incorrect 131 ms 4948 KB Output isn't correct
7 Incorrect 132 ms 4352 KB Output isn't correct
8 Correct 113 ms 4228 KB Output is correct
9 Incorrect 186 ms 15696 KB Output isn't correct
10 Incorrect 193 ms 15184 KB Output isn't correct
11 Incorrect 202 ms 15192 KB Output isn't correct
12 Incorrect 193 ms 13352 KB Output isn't correct
13 Correct 172 ms 17236 KB Output is correct
14 Incorrect 165 ms 10956 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 103 ms 7864 KB Output isn't correct
2 Incorrect 199 ms 13684 KB Output isn't correct
3 Incorrect 139 ms 15444 KB Output isn't correct
4 Incorrect 126 ms 12304 KB Output isn't correct
5 Incorrect 135 ms 12112 KB Output isn't correct
6 Incorrect 125 ms 12116 KB Output isn't correct
7 Incorrect 129 ms 10832 KB Output isn't correct
8 Incorrect 130 ms 15440 KB Output isn't correct
9 Incorrect 199 ms 15588 KB Output isn't correct
10 Incorrect 201 ms 15188 KB Output isn't correct
11 Incorrect 205 ms 15308 KB Output isn't correct
12 Incorrect 202 ms 13652 KB Output isn't correct
13 Incorrect 204 ms 19592 KB Output isn't correct
14 Incorrect 198 ms 11472 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1060 ms 15700 KB Time limit exceeded
2 Incorrect 201 ms 13652 KB Output isn't correct
3 Correct 177 ms 19540 KB Output is correct
4 Execution timed out 1045 ms 15700 KB Time limit exceeded
5 Incorrect 199 ms 15064 KB Output isn't correct
6 Incorrect 192 ms 15296 KB Output isn't correct
7 Incorrect 203 ms 13652 KB Output isn't correct
8 Correct 180 ms 19540 KB Output is correct
9 Incorrect 167 ms 10956 KB Output isn't correct