Submission #427260

# Submission time Handle Problem Language Result Execution time Memory
427260 2021-06-14T13:50:28 Z model_code Counterspells (CPSPC17_counterspells) C++17
60 / 100
2000 ms 2476 KB
#include <bits/stdc++.h>
using namespace std;

#define inf 1023456789
#define linf 1023456789123456789ll
#define pii pair<int,int>
#define pipii pair<int, pii >
#define pll pair<long long,long long>
#define vint vector<int>
#define vvint vector<vint >
#define ll long long
#define pdd pair<double, double>

#define DEBUG
#ifdef DEBUG
#define db(x) cerr << #x << " = " << x << endl
#else
#define db(x)
#endif

int main()
{
	int n;
	scanf("%d", &n);
	vint parent(1, -1);
	vector<bool> active(1, true);
	vint active_children(1, 0);
	for(int i=1; i<=n; i++)
	{
		int p;
		scanf("%d", &p);
		parent.push_back(p);
		active.push_back(true);
		active_children.push_back(0);
		int count = 0;
		active_children[p]++;
		for(int cur = parent[i]; cur != -1; cur = parent[cur])
		{
			if(active[cur] && active_children[cur] > 0)
			{
				active[cur] = false;
				count++;
				if(parent[cur] != -1) active_children[parent[cur]]--;
				continue;
			}
			if(!active[cur] && active_children[cur] == 0)
			{
				active[cur] = true;
				count++;
				if(parent[cur] != -1) active_children[parent[cur]]++;
				continue;
			}
			break;
		}
		printf("%d\n", count);
	}
	return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:24:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
Main.cpp:31:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |   scanf("%d", &p);
      |   ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 2 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
7 Correct 2 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 2 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
7 Correct 2 ms 204 KB Output is correct
8 Correct 3 ms 460 KB Output is correct
9 Correct 201 ms 392 KB Output is correct
10 Correct 3 ms 460 KB Output is correct
11 Correct 3 ms 460 KB Output is correct
12 Correct 3 ms 460 KB Output is correct
13 Correct 10 ms 380 KB Output is correct
14 Correct 37 ms 380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 2 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
7 Correct 2 ms 204 KB Output is correct
8 Correct 3 ms 460 KB Output is correct
9 Correct 201 ms 392 KB Output is correct
10 Correct 3 ms 460 KB Output is correct
11 Correct 3 ms 460 KB Output is correct
12 Correct 3 ms 460 KB Output is correct
13 Correct 10 ms 380 KB Output is correct
14 Correct 37 ms 380 KB Output is correct
15 Correct 34 ms 1404 KB Output is correct
16 Execution timed out 2064 ms 820 KB Time limit exceeded
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 69 ms 2400 KB Output is correct
2 Correct 56 ms 2448 KB Output is correct
3 Correct 41 ms 2324 KB Output is correct
4 Correct 51 ms 2476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 2 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
7 Correct 2 ms 204 KB Output is correct
8 Correct 3 ms 460 KB Output is correct
9 Correct 201 ms 392 KB Output is correct
10 Correct 3 ms 460 KB Output is correct
11 Correct 3 ms 460 KB Output is correct
12 Correct 3 ms 460 KB Output is correct
13 Correct 10 ms 380 KB Output is correct
14 Correct 37 ms 380 KB Output is correct
15 Correct 34 ms 1404 KB Output is correct
16 Execution timed out 2064 ms 820 KB Time limit exceeded
17 Halted 0 ms 0 KB -