답안 #30524

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
30524 2017-07-24T11:50:38 Z RezwanArefin01 Ball Machine (BOI13_ballmachine) C++14
0 / 100
1000 ms 17660 KB
//Bismillahir Rahmanir Rahim
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
vector<int> adj[maxn], post; 
int prior[maxn]; 
int MinDfs(int u) {
	if(!adj[u].size()) return u;
	for(int v : adj[u]) 
		prior[v] = MinDfs(v); 
	sort(adj[u].begin(), adj[u].end(), [](int a, int b) { return prior[a] < prior[b]; } ); 
} 
void postDfs(int u) {
	if(!adj[u].size()) { post.push_back(u); return; }
	for(int v : adj[u]) postDfs(v); 
	post.push_back(u);
}

struct node{
	int u, prior; 
	bool operator < (const node &p) const {
		return prior < p.prior; 
	}
};

int main(int argc, char const *argv[]) {
#ifdef LOCAL_TESTING
	freopen("in", "r", stdin);
#endif
	int n, q, root; cin>>n>>q; 
	for(int i = 1; i <= n; i++) {
		int p; cin>>p;
		if(p == 0) root = i;
		adj[p].push_back(i);  
	} 
	MinDfs(root); 
	postDfs(root); 
	set<node> Q; 
	for(int i = 0; i < n; i++) {
		Q.insert({post[i], i});
		prior[post[i]] = i;
	}
	while(q--) {
		int c, x; 
		cin>>c>>x; 
		if(c == 1) {
			node u; 
			while(x--) {
				u = *(Q.begin()); 
				Q.erase(Q.begin()); 
			} cout<<u.u<<endl;
		} else {
			auto it = Q.find({x, prior[x]}); 
			if(it != Q.end()) 
				Q.erase(it);
			cout<<0<<endl;
		}
	}

}

Compilation message

ballmachine.cpp: In function 'int MinDfs(int)':
ballmachine.cpp:13:1: warning: control reaches end of non-void function [-Wreturn-type]
 } 
 ^
ballmachine.cpp: In function 'int main(int, const char**)':
ballmachine.cpp:52:14: warning: 'u.node::u' may be used uninitialized in this function [-Wmaybe-uninitialized]
    } cout<<u.u<<endl;
              ^
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1000 ms 4756 KB Execution timed out
2 Runtime error 166 ms 9152 KB Execution timed out (wall clock limit exceeded)
3 Incorrect 216 ms 9152 KB Output isn't correct
4 Execution timed out 1000 ms 4756 KB Execution timed out
5 Execution timed out 1000 ms 4756 KB Execution timed out
6 Incorrect 0 ms 4888 KB Output isn't correct
7 Execution timed out 1000 ms 4888 KB Execution timed out
8 Execution timed out 1000 ms 4888 KB Execution timed out
9 Execution timed out 1000 ms 5020 KB Execution timed out
10 Execution timed out 1000 ms 5812 KB Execution timed out
11 Execution timed out 1000 ms 9152 KB Execution timed out
12 Runtime error 213 ms 9152 KB Execution timed out (wall clock limit exceeded)
13 Runtime error 183 ms 9152 KB Execution timed out (wall clock limit exceeded)
# 결과 실행 시간 메모리 Grader output
1 Runtime error 66 ms 7056 KB Execution timed out (wall clock limit exceeded)
2 Runtime error 309 ms 14132 KB Execution timed out (wall clock limit exceeded)
3 Runtime error 339 ms 11392 KB Execution timed out (wall clock limit exceeded)
4 Execution timed out 1000 ms 7576 KB Execution timed out
5 Execution timed out 1000 ms 7444 KB Execution timed out
6 Execution timed out 1000 ms 7448 KB Execution timed out
7 Execution timed out 1000 ms 6888 KB Execution timed out
8 Execution timed out 1000 ms 7060 KB Execution timed out
9 Execution timed out 1000 ms 14564 KB Execution timed out
10 Runtime error 276 ms 14136 KB Execution timed out (wall clock limit exceeded)
11 Runtime error 269 ms 14140 KB Execution timed out (wall clock limit exceeded)
12 Runtime error 286 ms 12764 KB Execution timed out (wall clock limit exceeded)
13 Runtime error 236 ms 16212 KB Execution timed out (wall clock limit exceeded)
14 Runtime error 223 ms 11392 KB Execution timed out (wall clock limit exceeded)
# 결과 실행 시간 메모리 Grader output
1 Incorrect 153 ms 9568 KB Output isn't correct
2 Runtime error 273 ms 12968 KB Execution timed out (wall clock limit exceeded)
3 Incorrect 203 ms 15168 KB Output isn't correct
4 Incorrect 229 ms 12696 KB Output isn't correct
5 Incorrect 199 ms 12356 KB Output isn't correct
6 Runtime error 193 ms 12360 KB Execution timed out (wall clock limit exceeded)
7 Runtime error 266 ms 11424 KB Execution timed out (wall clock limit exceeded)
8 Runtime error 236 ms 15168 KB Execution timed out (wall clock limit exceeded)
9 Runtime error 349 ms 14560 KB Execution timed out (wall clock limit exceeded)
10 Incorrect 253 ms 14144 KB Output isn't correct
11 Runtime error 213 ms 14148 KB Execution timed out (wall clock limit exceeded)
12 Runtime error 246 ms 12964 KB Execution timed out (wall clock limit exceeded)
13 Incorrect 289 ms 17660 KB Output isn't correct
14 Runtime error 299 ms 11396 KB Execution timed out (wall clock limit exceeded)
# 결과 실행 시간 메모리 Grader output
1 Runtime error 286 ms 14556 KB Execution timed out (wall clock limit exceeded)
2 Runtime error 249 ms 12968 KB Execution timed out (wall clock limit exceeded)
3 Runtime error 249 ms 17652 KB Execution timed out (wall clock limit exceeded)
4 Runtime error 219 ms 14552 KB Execution timed out (wall clock limit exceeded)
5 Execution timed out 1000 ms 14144 KB Execution timed out
6 Runtime error 276 ms 14148 KB Execution timed out (wall clock limit exceeded)
7 Runtime error 359 ms 12968 KB Execution timed out (wall clock limit exceeded)
8 Runtime error 273 ms 17656 KB Execution timed out (wall clock limit exceeded)
9 Runtime error 246 ms 11396 KB Execution timed out (wall clock limit exceeded)