제출 #755469

#제출 시각아이디문제언어결과실행 시간메모리
755469dxz05Ball Machine (BOI13_ballmachine)C++17
60.08 / 100
1094 ms18704 KiB
#pragma GCC optimize("Ofast,O3,unroll-loops") #pragma GCC target("avx2") #include <bits/stdc++.h> using namespace std; #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define bpc(x) __builtin_popcount(x) #define bpcll(x) __builtin_popcountll(x) #define MP make_pair //#define endl '\n' mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); typedef long long ll; const int MOD = 1e9 + 7; const int N = 1e5 + 3e2; int p[N]; vector<int> g[N]; int sub_min[N]; void dfs0(int v){ sub_min[v] = v; for (int u : g[v]){ dfs0(u); sub_min[v] = min(sub_min[v], sub_min[u]); } } int order[N], vertex[N]; int timer = 0; void traversal(int v){ sort(all(g[v]), [&](int x, int y){ return sub_min[x] < sub_min[y]; }); for (int u : g[v]) traversal(u); timer++; order[v] = timer; vertex[timer] = v; } bool flag[N]; void solve(){ int n, q; cin >> n >> q; int root = 0; for (int i = 1; i <= n; i++){ cin >> p[i]; if (p[i] != 0){ g[p[i]].push_back(i); } else { root = i; } } dfs0(root); traversal(root); set<int> free; for (int i = 1; i <= n; i++) free.insert(i); while (q--){ int t; cin >> t; if (t == 1){ int k; cin >> k; int last = 0; while (k--){ int v = *free.begin(); free.erase(free.begin()); v = vertex[v]; flag[v] = true; last = v; } cout << last << endl; } else { int v; cin >> v; int last = v, cnt = 0; while (v != 0 && flag[v]){ cnt++; last = v; v = p[v]; } flag[last] = false; free.insert(order[last]); cout << --cnt << endl; } } } int main(){ clock_t startTime = clock(); ios_base::sync_with_stdio(false); #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int test_cases = 1; // cin >> test_cases; for (int test = 1; test <= test_cases; test++){ // cout << (solve() ? "YES" : "NO") << endl; solve(); } #ifdef LOCAL cerr << "Time: " << int((double) (clock() - startTime) / CLOCKS_PER_SEC * 1000) << " ms" << endl; #endif return 0; }

컴파일 시 표준 에러 (stderr) 메시지

ballmachine.cpp: In function 'int main()':
ballmachine.cpp:107:13: warning: unused variable 'startTime' [-Wunused-variable]
  107 |     clock_t startTime = clock();
      |             ^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...