Submission #406378

# Submission time Handle Problem Language Result Execution time Memory
406378 2021-05-17T13:47:26 Z EncryptingWolf Toy Train (IOI17_train) C++14
49 / 100
2000 ms 3148 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_set>
#include <tuple>
//typedef long long int;
#define FOR(i,x,y) for(int i = x; i < y; i++)
using namespace std;

vector<int> players;
vector<unordered_set<int>> adj;
vector<int> inCounts;

unordered_set<int> badNodesF;
unordered_set<int> batteries;
unordered_set<int> nodesLeft;
#include <stack>

void dfs(bool playerWants, unordered_set<int>& badNodes, vector<int>& visited, vector<int>& starts)
{
	vector<pair<int,int>> s;
	s.reserve(starts.size());
	for (auto i : starts)
		s.push_back({ i,true });
	while (s.size())
	{
		int node = s[s.size() - 1].first;
		bool losing = s[s.size() - 1].second;
		s.pop_back();
		/*if (badNodesF.count(node))
			continue;*/

		visited[node]++;
		if (players[node] == playerWants)
		{
			if (visited[node] != 1)
				continue;
			else
			{
				badNodes.emplace(node);
			}
		}
		else
		{
			if (losing&&visited[node] <= inCounts[node])
			{
				visited[node] = inCounts[node] + 2; badNodes.emplace(node);
			}
			else {
				if (visited[node] != inCounts[node])
				{
					continue;
				}
				else
				{

					badNodes.emplace(node);
				}
			}
		}

		for (auto i : adj[node])
		{
			//dfs(i, playerWants, badNodes, visited, false);
			s.push_back({ i,false });
		}
	}
}


vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v)
{
	int n = a.size();
	players = a;
	inCounts.resize(n);

	adj.resize(n);
	FOR(i, 0, u.size())
	{
		adj[v[i]].emplace(u[i]);
		inCounts[u[i]] += 1;

	}
	FOR(i, 0, n)
	{
		if (r[i])
			batteries.emplace(i);
		nodesLeft.emplace(i);
	}
	vector<int> visited2(n);
	vector<int> visited(n);

	while (true)
	{
		for (auto i : nodesLeft)
		{
			visited[i] = 0;
			visited2[i] = 0;
		}
		unordered_set<int> badNodes;

		vector<int> s;
		for (auto i : batteries)
		{

			badNodes.emplace(i);
			s.push_back(i);
		}
		dfs(true, badNodes, visited, s);

		unordered_set<int> badNodes2;

		vector<int> k;
		for (auto i : nodesLeft)
		{
			if (badNodes.count(i) == 0 && badNodesF.count(i) == 0)
			{
				badNodes2.emplace(i);
				k.push_back(i);
			}
		}

		dfs(false, badNodes2, visited2, k);
		for (auto i : badNodes2)
		{
			//			if (badNodes2.count(i))
				//		{
			r[i] = 0;
			batteries.erase(i);
			//	}
		}
		if (badNodes2.size() == 0)
			break;


		/*for (auto i : badNodes2)
			cout << i;*/
			//cout << endl;
			//badNodesF = badNodes2;

		for (auto j : nodesLeft)
		{
			auto& i = adj[j];
			for (auto j : badNodes2)
			{
				i.erase(j);
			}

		}
		for (auto i : badNodes2)
		{
			nodesLeft.erase(i);
			badNodesF.emplace(i);
			for (auto j : adj[i])
				inCounts[j]--;
		}

	}

	// !badNodes is B
	// Badnodes2 are B
	// Neither is B
	vector<int> re;
	FOR(i, 0, n)
	{
		if (badNodesF.count(i))
			re.push_back(0);
		else
			re.push_back(1);
	}
	return re;
}

Compilation message

train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:8:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 | #define FOR(i,x,y) for(int i = x; i < y; i++)
......
   79 |  FOR(i, 0, u.size())
      |      ~~~~~~~~~~~~~~                  
train.cpp:79:2: note: in expansion of macro 'FOR'
   79 |  FOR(i, 0, u.size())
      |  ^~~
# Verdict Execution time Memory Grader output
1 Correct 110 ms 2316 KB Output is correct
2 Correct 115 ms 2272 KB Output is correct
3 Correct 118 ms 2272 KB Output is correct
4 Correct 126 ms 2252 KB Output is correct
5 Correct 125 ms 2252 KB Output is correct
6 Correct 109 ms 2248 KB Output is correct
7 Correct 185 ms 2324 KB Output is correct
8 Correct 46 ms 2192 KB Output is correct
9 Correct 123 ms 2196 KB Output is correct
10 Correct 117 ms 2176 KB Output is correct
11 Correct 107 ms 2180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 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 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 288 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 296 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 292 KB Output is correct
20 Correct 1 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 616 ms 3028 KB Output is correct
2 Correct 986 ms 3024 KB Output is correct
3 Correct 1259 ms 3052 KB Output is correct
4 Correct 17 ms 2892 KB Output is correct
5 Correct 106 ms 2884 KB Output is correct
6 Correct 215 ms 2840 KB Output is correct
7 Correct 13 ms 3020 KB Output is correct
8 Correct 163 ms 2944 KB Output is correct
9 Correct 234 ms 2876 KB Output is correct
10 Correct 86 ms 2852 KB Output is correct
11 Correct 137 ms 2712 KB Output is correct
12 Correct 231 ms 2764 KB Output is correct
13 Correct 15 ms 2892 KB Output is correct
14 Correct 15 ms 2872 KB Output is correct
15 Correct 15 ms 2892 KB Output is correct
16 Correct 16 ms 2864 KB Output is correct
17 Correct 12 ms 2864 KB Output is correct
18 Correct 1761 ms 2436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 2688 KB Output is correct
2 Correct 98 ms 2636 KB Output is correct
3 Correct 233 ms 2912 KB Output is correct
4 Correct 284 ms 3124 KB Output is correct
5 Correct 182 ms 2936 KB Output is correct
6 Correct 118 ms 2892 KB Output is correct
7 Correct 120 ms 2888 KB Output is correct
8 Correct 262 ms 2928 KB Output is correct
9 Correct 89 ms 2948 KB Output is correct
10 Correct 16 ms 2972 KB Output is correct
11 Correct 21 ms 3080 KB Output is correct
12 Correct 15 ms 2996 KB Output is correct
13 Correct 151 ms 2828 KB Output is correct
14 Correct 100 ms 2716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 170 ms 2916 KB Output is correct
2 Correct 15 ms 2764 KB Output is correct
3 Correct 88 ms 2836 KB Output is correct
4 Correct 13 ms 2636 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 192 ms 2008 KB Output is correct
7 Correct 17 ms 1740 KB Output is correct
8 Correct 16 ms 1784 KB Output is correct
9 Correct 14 ms 1828 KB Output is correct
10 Correct 3 ms 716 KB Output is correct
11 Correct 9 ms 1612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 110 ms 2316 KB Output is correct
2 Correct 115 ms 2272 KB Output is correct
3 Correct 118 ms 2272 KB Output is correct
4 Correct 126 ms 2252 KB Output is correct
5 Correct 125 ms 2252 KB Output is correct
6 Correct 109 ms 2248 KB Output is correct
7 Correct 185 ms 2324 KB Output is correct
8 Correct 46 ms 2192 KB Output is correct
9 Correct 123 ms 2196 KB Output is correct
10 Correct 117 ms 2176 KB Output is correct
11 Correct 107 ms 2180 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 288 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 296 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 292 KB Output is correct
31 Correct 1 ms 256 KB Output is correct
32 Correct 616 ms 3028 KB Output is correct
33 Correct 986 ms 3024 KB Output is correct
34 Correct 1259 ms 3052 KB Output is correct
35 Correct 17 ms 2892 KB Output is correct
36 Correct 106 ms 2884 KB Output is correct
37 Correct 215 ms 2840 KB Output is correct
38 Correct 13 ms 3020 KB Output is correct
39 Correct 163 ms 2944 KB Output is correct
40 Correct 234 ms 2876 KB Output is correct
41 Correct 86 ms 2852 KB Output is correct
42 Correct 137 ms 2712 KB Output is correct
43 Correct 231 ms 2764 KB Output is correct
44 Correct 15 ms 2892 KB Output is correct
45 Correct 15 ms 2872 KB Output is correct
46 Correct 15 ms 2892 KB Output is correct
47 Correct 16 ms 2864 KB Output is correct
48 Correct 12 ms 2864 KB Output is correct
49 Correct 1761 ms 2436 KB Output is correct
50 Correct 12 ms 2688 KB Output is correct
51 Correct 98 ms 2636 KB Output is correct
52 Correct 233 ms 2912 KB Output is correct
53 Correct 284 ms 3124 KB Output is correct
54 Correct 182 ms 2936 KB Output is correct
55 Correct 118 ms 2892 KB Output is correct
56 Correct 120 ms 2888 KB Output is correct
57 Correct 262 ms 2928 KB Output is correct
58 Correct 89 ms 2948 KB Output is correct
59 Correct 16 ms 2972 KB Output is correct
60 Correct 21 ms 3080 KB Output is correct
61 Correct 15 ms 2996 KB Output is correct
62 Correct 151 ms 2828 KB Output is correct
63 Correct 100 ms 2716 KB Output is correct
64 Correct 170 ms 2916 KB Output is correct
65 Correct 15 ms 2764 KB Output is correct
66 Correct 88 ms 2836 KB Output is correct
67 Correct 13 ms 2636 KB Output is correct
68 Correct 2 ms 332 KB Output is correct
69 Correct 192 ms 2008 KB Output is correct
70 Correct 17 ms 1740 KB Output is correct
71 Correct 16 ms 1784 KB Output is correct
72 Correct 14 ms 1828 KB Output is correct
73 Correct 3 ms 716 KB Output is correct
74 Correct 9 ms 1612 KB Output is correct
75 Correct 841 ms 2968 KB Output is correct
76 Correct 1004 ms 3020 KB Output is correct
77 Correct 1317 ms 3140 KB Output is correct
78 Correct 1231 ms 3148 KB Output is correct
79 Correct 1268 ms 3072 KB Output is correct
80 Correct 14 ms 2892 KB Output is correct
81 Correct 219 ms 2896 KB Output is correct
82 Correct 155 ms 2868 KB Output is correct
83 Correct 111 ms 2760 KB Output is correct
84 Correct 171 ms 2816 KB Output is correct
85 Correct 208 ms 2872 KB Output is correct
86 Correct 176 ms 2832 KB Output is correct
87 Correct 221 ms 2892 KB Output is correct
88 Correct 203 ms 2852 KB Output is correct
89 Correct 184 ms 2940 KB Output is correct
90 Correct 212 ms 2716 KB Output is correct
91 Correct 220 ms 2832 KB Output is correct
92 Correct 213 ms 2860 KB Output is correct
93 Correct 225 ms 2808 KB Output is correct
94 Correct 221 ms 2836 KB Output is correct
95 Correct 212 ms 2840 KB Output is correct
96 Correct 348 ms 2672 KB Output is correct
97 Correct 1314 ms 2992 KB Output is correct
98 Correct 1895 ms 2888 KB Output is correct
99 Execution timed out 2079 ms 2892 KB Time limit exceeded
100 Halted 0 ms 0 KB -