답안 #406360

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
406360 2021-05-17T12:57:15 Z EncryptingWolf 장난감 기차 (IOI17_train) C++14
38 / 100
2000 ms 2940 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <tuple>
typedef long long ll;
#define FOR(i,x,y) for(ll i = x; i < y; i++)
using namespace std;

vector<int> players;
vector<set<ll>> adj;
vector<ll> inCounts;
set<ll> badNodesF;
set<ll> batteries;
set<ll> nodesLeft;

void dfs(ll node, bool playerWants, set<ll>& badNodes, vector<ll>& visited, bool losing)
{
	if (badNodesF.count(node))
		return;
	visited[node]++;
	if (players[node] == playerWants)
	{
		if (visited[node] != 1)
			return;
		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])
			{
				return;
			}
			else
			{

				badNodes.emplace(node);
			}
		}
	}

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


vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v)
{
	ll 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);
	}
	while (true)
	{
		vector<ll> visited(n);
		set<ll> badNodes;
		for (auto i : batteries)
		{

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

		set<ll> badNodes2;
		vector<ll> visited2(n);

		for (auto i : nodesLeft)
		{
			if (badNodes.count(i) == 0 && badNodesF.count(i)==0)
			{
				badNodes2.emplace(i);
				dfs(i, false, badNodes2, visited2, true);
			}
		}

		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:36: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 | #define FOR(i,x,y) for(ll i = x; i < y; i++)
......
   65 |  FOR(i, 0, u.size())
      |      ~~~~~~~~~~~~~~                 
train.cpp:65:2: note: in expansion of macro 'FOR'
   65 |  FOR(i, 0, u.size())
      |  ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 174 ms 1884 KB Output is correct
2 Correct 200 ms 1900 KB Output is correct
3 Correct 173 ms 1988 KB Output is correct
4 Correct 187 ms 1868 KB Output is correct
5 Correct 182 ms 1876 KB Output is correct
6 Correct 180 ms 1872 KB Output is correct
7 Correct 349 ms 1868 KB Output is correct
8 Correct 49 ms 1740 KB Output is correct
9 Correct 180 ms 1868 KB Output is correct
10 Correct 172 ms 1800 KB Output is correct
11 Correct 147 ms 1704 KB Output is correct
# 결과 실행 시간 메모리 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 300 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 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 300 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 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1641 ms 2892 KB Output is correct
2 Execution timed out 2092 ms 2912 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 2508 KB Output is correct
2 Correct 156 ms 2480 KB Output is correct
3 Correct 489 ms 2700 KB Output is correct
4 Correct 499 ms 2940 KB Output is correct
5 Correct 309 ms 2620 KB Output is correct
6 Correct 174 ms 2644 KB Output is correct
7 Correct 200 ms 2692 KB Output is correct
8 Correct 486 ms 2672 KB Output is correct
9 Correct 150 ms 2740 KB Output is correct
10 Correct 18 ms 2764 KB Output is correct
11 Correct 14 ms 2868 KB Output is correct
12 Correct 15 ms 2796 KB Output is correct
13 Correct 245 ms 2636 KB Output is correct
14 Correct 155 ms 2508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 236 ms 2708 KB Output is correct
2 Correct 14 ms 2764 KB Output is correct
3 Correct 113 ms 2608 KB Output is correct
4 Correct 13 ms 2508 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 504 ms 1696 KB Output is correct
7 Correct 15 ms 1576 KB Output is correct
8 Correct 20 ms 1708 KB Output is correct
9 Correct 15 ms 1612 KB Output is correct
10 Correct 4 ms 588 KB Output is correct
11 Correct 12 ms 1612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 174 ms 1884 KB Output is correct
2 Correct 200 ms 1900 KB Output is correct
3 Correct 173 ms 1988 KB Output is correct
4 Correct 187 ms 1868 KB Output is correct
5 Correct 182 ms 1876 KB Output is correct
6 Correct 180 ms 1872 KB Output is correct
7 Correct 349 ms 1868 KB Output is correct
8 Correct 49 ms 1740 KB Output is correct
9 Correct 180 ms 1868 KB Output is correct
10 Correct 172 ms 1800 KB Output is correct
11 Correct 147 ms 1704 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 300 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 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 300 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 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1641 ms 2892 KB Output is correct
33 Execution timed out 2092 ms 2912 KB Time limit exceeded
34 Halted 0 ms 0 KB -