Submission #427262

# Submission time Handle Problem Language Result Execution time Memory
427262 2021-06-14T13:50:53 Z model_code Counterspells (CPSPC17_counterspells) C++17
40 / 100
2000 ms 9832 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);
	vvint son(1);
	vint parent(1, -1);
	vector<bool> active(1, true);
	for(int i=1; i<=n; i++)
	{
		int p;
		scanf("%d", &p);
		parent.push_back(p);
		son.push_back(vint(0));
		active.push_back(true);
		son[p].push_back(i);
		int count = 0;
		for(int cur = parent[i]; cur != -1; cur = parent[cur])
		{
			bool old = active[cur];
			active[cur] = true;
			for(int j=0; j<son[cur].size(); j++)
			{
				if(active[son[cur][j]])
				{
					active[cur] = false;
					break;
				}
			}
			if(active[cur] != old)count++;
			else break;
		}
		printf("%d\n", count);
	}
	return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:41:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |    for(int j=0; j<son[cur].size(); j++)
      |                 ~^~~~~~~~~~~~~~~~
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 332 KB Output is correct
2 Correct 3 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 3 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 4 ms 844 KB Output is correct
9 Correct 232 ms 1036 KB Output is correct
10 Correct 3 ms 844 KB Output is correct
11 Correct 3 ms 844 KB Output is correct
12 Correct 31 ms 968 KB Output is correct
13 Correct 13 ms 972 KB Output is correct
14 Correct 37 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 3 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 4 ms 844 KB Output is correct
9 Correct 232 ms 1036 KB Output is correct
10 Correct 3 ms 844 KB Output is correct
11 Correct 3 ms 844 KB Output is correct
12 Correct 31 ms 968 KB Output is correct
13 Correct 13 ms 972 KB Output is correct
14 Correct 37 ms 716 KB Output is correct
15 Correct 42 ms 5064 KB Output is correct
16 Execution timed out 2094 ms 2088 KB Time limit exceeded
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 123 ms 9832 KB Output is correct
2 Correct 89 ms 9696 KB Output is correct
3 Correct 45 ms 8532 KB Output is correct
4 Execution timed out 2035 ms 5152 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 3 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 4 ms 844 KB Output is correct
9 Correct 232 ms 1036 KB Output is correct
10 Correct 3 ms 844 KB Output is correct
11 Correct 3 ms 844 KB Output is correct
12 Correct 31 ms 968 KB Output is correct
13 Correct 13 ms 972 KB Output is correct
14 Correct 37 ms 716 KB Output is correct
15 Correct 42 ms 5064 KB Output is correct
16 Execution timed out 2094 ms 2088 KB Time limit exceeded
17 Halted 0 ms 0 KB -