답안 #291475

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
291475 2020-09-05T11:05:50 Z abyyskit 장난감 기차 (IOI17_train) C++14
37 / 100
1371 ms 1528 KB
#include "train.h"
#include<bits/stdc++.h>
using namespace std;
#define FOR(i, x, y) for(int i = x; i < y; ++i)
#define pb push_back


struct node{
	vector<int> e;
	bool charge = false;
	bool A = false;
	bool vis = false;
	int time = INT_MAX;
	bool pos = false;
};

vector<node> g;

vector<int> subtask1(){
	vector<int> ans(g.size(), 0);
	for(int i = g.size() - 1; i >= 0; --i){
		if (g[i].A){
			ans[i] = 0;
		}
		else{
			ans[i] = 1;
		}
		FOR(j, 0, g[i].e.size()){
			int nex = g[i].e[j];
		//	cout << "nex: " << nex << "\n";
			if (g[i].A){
				if (g[i].charge && nex == i){
					ans[i] = 1;
					break;
				}
				if (nex != i){
					ans[i] = max(ans[i], ans[i + 1]);
				}
			}
			else{
				if (nex == i){
					if (!g[i].charge){
						ans[i] = 0;
						break;
					}
				}
				else{
					ans[i] = min(ans[i], ans[i + 1]);
				}
			}
		}
	}
	return ans;
}

int s2dfs(int start, int prev){
	g[start].vis = true;
	if (g[start].charge){
		prev = g[start].time;
	}
	int ans;
	if (g[start].A){
		ans = 0;
	}
	else{
		ans = 1;
	}
	FOR(i, 0, g[start].e.size()){
		int nex = g[start].e[i];
		if (!g[nex].vis){
			g[nex].time = g[start].time + 1;
			int tmp = s2dfs(nex, prev);
			if (g[start].A){
				ans = max(ans, tmp);
			}
			else{
				ans = min(ans, tmp);
			}
		}
		else{
			if (g[nex].time <= prev){
				if (g[start].A){
					ans = 1;
				}	
			}
			else{
				if (!g[start].A){
					ans = 0;
				}
			}
		}
	}
	g[start].time = INT_MAX;
	g[start].vis = false;
	return ans;
}


vector<int> subtask2(){
	vector<int> ans(g.size(), 0);
	FOR(i, 0, g.size()){
		g[i].time = 0;
		ans[i] = s2dfs(i, -1);
		g[i].time = INT_MAX;
	}
	return ans;
}

void reset(){
	FOR(i, 0, g.size()){
		g[i].vis = false;
	}
}

void mark(int cur, int start){
	g[cur].vis = true;
	FOR(i, 0, g[cur].e.size()){
		int nex = g[cur].e[i];
		if (nex == start){
			g[cur].pos = true;
		}
		if (!g[nex].vis){
			mark(nex, start);
		}
		if (g[nex].pos){
			g[cur].pos = true;
		}
	}

}


vector<int> subtask3(){
	vector<int> ans(g.size(), 0);
	FOR(i, 0, g.size()){
		if (g[i].charge){
			reset();
			mark(i, i);
		}
	}
	FOR(i, 0, g.size()){
		if (g[i].pos){
			ans[i] = 1;
		}
		else{
			reset();
			mark(i, -1);
		}
		if (g[i].pos) ans[i] = 1;
	}
	return ans;
}

void Mark(int cur, int start){
	g[cur].vis = true;
	FOR(i, 0, g[cur].e.size()){
		int nex = g[cur].e[i];
		if (!g[nex].charge){
			if (nex == start){
				g[cur].pos = true;
			}
			if (!g[nex].vis && !g[nex].pos){
				Mark(nex, start);
			}
			if (g[nex].pos){
				g[cur].pos = true;
			}
		}
	}
}

void check(int start){
	g[start].vis = true;
	FOR(i, 0, g[start].e.size()){
		int nex = g[start].e[i];
		if (!g[nex].vis && !g[nex].pos){
			check(nex);
		}
		if (g[nex].pos){
			g[start].pos = true;
		}
	}
}

vector<int> subtask4(){
	vector<int> ans(g.size(), 1);
	FOR(i, 0, g.size()){
		if (!g[i].charge){
			reset();
			Mark(i, i);
		}
	}
	FOR(i, 0, g.size()){
		if (g[i].pos){
			ans[i] = 0;
		}
		else{
			reset();
			check(i);
		}
		if (g[i].pos){
			ans[i] = 0;
		}


	}
	return ans;

}


vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v){
	g.resize(a.size());
	FOR(i, 0, u.size()){
		g[u[i]].e.pb(v[i]);
	}
//	cout << "here\n";
	int sum = 0;
	FOR(i, 0, a.size()){
		if (a[i] == 1){
			sum++;
			g[i].A = true;
		}
		if (r[i] == 1){
			g[i].charge = true;
		}
	}
	if (a.size() <= 15){
		return subtask2();
	}
	else if (sum == a.size()){
		return subtask3();
	}
	else if (sum == 0){
		return subtask4();
	}
	else{
		return subtask1();
	}
}

Compilation message

train.cpp: In function 'std::vector<int> subtask1()':
train.cpp:4:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define FOR(i, x, y) for(int i = x; i < y; ++i)
......
   28 |   FOR(j, 0, g[i].e.size()){
      |       ~~~~~~~~~~~~~~~~~~~              
train.cpp:28:3: note: in expansion of macro 'FOR'
   28 |   FOR(j, 0, g[i].e.size()){
      |   ^~~
train.cpp: In function 'int s2dfs(int, int)':
train.cpp:4:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define FOR(i, x, y) for(int i = x; i < y; ++i)
......
   68 |  FOR(i, 0, g[start].e.size()){
      |      ~~~~~~~~~~~~~~~~~~~~~~~           
train.cpp:68:2: note: in expansion of macro 'FOR'
   68 |  FOR(i, 0, g[start].e.size()){
      |  ^~~
train.cpp: In function 'std::vector<int> subtask2()':
train.cpp:4:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<node>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define FOR(i, x, y) for(int i = x; i < y; ++i)
......
  101 |  FOR(i, 0, g.size()){
      |      ~~~~~~~~~~~~~~                    
train.cpp:101:2: note: in expansion of macro 'FOR'
  101 |  FOR(i, 0, g.size()){
      |  ^~~
train.cpp: In function 'void reset()':
train.cpp:4:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<node>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define FOR(i, x, y) for(int i = x; i < y; ++i)
......
  110 |  FOR(i, 0, g.size()){
      |      ~~~~~~~~~~~~~~                    
train.cpp:110:2: note: in expansion of macro 'FOR'
  110 |  FOR(i, 0, g.size()){
      |  ^~~
train.cpp: In function 'void mark(int, int)':
train.cpp:4:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define FOR(i, x, y) for(int i = x; i < y; ++i)
......
  117 |  FOR(i, 0, g[cur].e.size()){
      |      ~~~~~~~~~~~~~~~~~~~~~             
train.cpp:117:2: note: in expansion of macro 'FOR'
  117 |  FOR(i, 0, g[cur].e.size()){
      |  ^~~
train.cpp: In function 'std::vector<int> subtask3()':
train.cpp:4:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<node>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define FOR(i, x, y) for(int i = x; i < y; ++i)
......
  135 |  FOR(i, 0, g.size()){
      |      ~~~~~~~~~~~~~~                    
train.cpp:135:2: note: in expansion of macro 'FOR'
  135 |  FOR(i, 0, g.size()){
      |  ^~~
train.cpp:4:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<node>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define FOR(i, x, y) for(int i = x; i < y; ++i)
......
  141 |  FOR(i, 0, g.size()){
      |      ~~~~~~~~~~~~~~                    
train.cpp:141:2: note: in expansion of macro 'FOR'
  141 |  FOR(i, 0, g.size()){
      |  ^~~
train.cpp: In function 'void Mark(int, int)':
train.cpp:4:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define FOR(i, x, y) for(int i = x; i < y; ++i)
......
  156 |  FOR(i, 0, g[cur].e.size()){
      |      ~~~~~~~~~~~~~~~~~~~~~             
train.cpp:156:2: note: in expansion of macro 'FOR'
  156 |  FOR(i, 0, g[cur].e.size()){
      |  ^~~
train.cpp: In function 'void check(int)':
train.cpp:4:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define FOR(i, x, y) for(int i = x; i < y; ++i)
......
  174 |  FOR(i, 0, g[start].e.size()){
      |      ~~~~~~~~~~~~~~~~~~~~~~~           
train.cpp:174:2: note: in expansion of macro 'FOR'
  174 |  FOR(i, 0, g[start].e.size()){
      |  ^~~
train.cpp: In function 'std::vector<int> subtask4()':
train.cpp:4:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<node>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define FOR(i, x, y) for(int i = x; i < y; ++i)
......
  187 |  FOR(i, 0, g.size()){
      |      ~~~~~~~~~~~~~~                    
train.cpp:187:2: note: in expansion of macro 'FOR'
  187 |  FOR(i, 0, g.size()){
      |  ^~~
train.cpp:4:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<node>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define FOR(i, x, y) for(int i = x; i < y; ++i)
......
  193 |  FOR(i, 0, g.size()){
      |      ~~~~~~~~~~~~~~                    
train.cpp:193:2: note: in expansion of macro 'FOR'
  193 |  FOR(i, 0, g.size()){
      |  ^~~
train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:4:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define FOR(i, x, y) for(int i = x; i < y; ++i)
......
  214 |  FOR(i, 0, u.size()){
      |      ~~~~~~~~~~~~~~                    
train.cpp:214:2: note: in expansion of macro 'FOR'
  214 |  FOR(i, 0, u.size()){
      |  ^~~
train.cpp:4:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define FOR(i, x, y) for(int i = x; i < y; ++i)
......
  219 |  FOR(i, 0, a.size()){
      |      ~~~~~~~~~~~~~~                    
train.cpp:219:2: note: in expansion of macro 'FOR'
  219 |  FOR(i, 0, a.size()){
      |  ^~~
train.cpp:231:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  231 |  else if (sum == a.size()){
      |           ~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 896 KB Output is correct
2 Correct 5 ms 896 KB Output is correct
3 Correct 5 ms 896 KB Output is correct
4 Correct 5 ms 896 KB Output is correct
5 Correct 5 ms 896 KB Output is correct
6 Correct 5 ms 896 KB Output is correct
7 Correct 20 ms 896 KB Output is correct
8 Correct 16 ms 896 KB Output is correct
9 Correct 5 ms 896 KB Output is correct
10 Correct 4 ms 896 KB Output is correct
11 Correct 4 ms 896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 110 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 3 ms 256 KB Output is correct
9 Correct 42 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 25 ms 256 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Correct 0 ms 256 KB Output is correct
17 Correct 1 ms 256 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 0 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 230 ms 1528 KB Output is correct
2 Correct 251 ms 1400 KB Output is correct
3 Correct 279 ms 1364 KB Output is correct
4 Correct 502 ms 1324 KB Output is correct
5 Correct 167 ms 1280 KB Output is correct
6 Correct 734 ms 1220 KB Output is correct
7 Correct 275 ms 1280 KB Output is correct
8 Correct 135 ms 1152 KB Output is correct
9 Correct 367 ms 1108 KB Output is correct
10 Correct 40 ms 1272 KB Output is correct
11 Correct 81 ms 1280 KB Output is correct
12 Correct 58 ms 1024 KB Output is correct
13 Correct 31 ms 1280 KB Output is correct
14 Correct 36 ms 1280 KB Output is correct
15 Correct 32 ms 1280 KB Output is correct
16 Correct 43 ms 1280 KB Output is correct
17 Correct 40 ms 1280 KB Output is correct
18 Correct 608 ms 1152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1030 ms 1132 KB Output is correct
2 Correct 166 ms 1124 KB Output is correct
3 Correct 128 ms 1152 KB Output is correct
4 Correct 21 ms 1280 KB Output is correct
5 Correct 224 ms 1200 KB Output is correct
6 Correct 393 ms 1196 KB Output is correct
7 Correct 334 ms 1272 KB Output is correct
8 Correct 57 ms 1152 KB Output is correct
9 Correct 37 ms 1152 KB Output is correct
10 Correct 1314 ms 1432 KB Output is correct
11 Correct 1338 ms 1400 KB Output is correct
12 Correct 1371 ms 1528 KB Output is correct
13 Correct 96 ms 1152 KB Output is correct
14 Correct 123 ms 1164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 1152 KB 3rd lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 896 KB Output is correct
2 Correct 5 ms 896 KB Output is correct
3 Correct 5 ms 896 KB Output is correct
4 Correct 5 ms 896 KB Output is correct
5 Correct 5 ms 896 KB Output is correct
6 Correct 5 ms 896 KB Output is correct
7 Correct 20 ms 896 KB Output is correct
8 Correct 16 ms 896 KB Output is correct
9 Correct 5 ms 896 KB Output is correct
10 Correct 4 ms 896 KB Output is correct
11 Correct 4 ms 896 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 110 ms 256 KB Output is correct
16 Correct 1 ms 256 KB Output is correct
17 Correct 1 ms 256 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 3 ms 256 KB Output is correct
20 Correct 42 ms 256 KB Output is correct
21 Correct 1 ms 256 KB Output is correct
22 Correct 25 ms 256 KB Output is correct
23 Correct 1 ms 256 KB Output is correct
24 Correct 0 ms 256 KB Output is correct
25 Correct 0 ms 256 KB Output is correct
26 Correct 0 ms 256 KB Output is correct
27 Correct 0 ms 256 KB Output is correct
28 Correct 1 ms 256 KB Output is correct
29 Correct 1 ms 256 KB Output is correct
30 Correct 0 ms 256 KB Output is correct
31 Correct 0 ms 256 KB Output is correct
32 Correct 230 ms 1528 KB Output is correct
33 Correct 251 ms 1400 KB Output is correct
34 Correct 279 ms 1364 KB Output is correct
35 Correct 502 ms 1324 KB Output is correct
36 Correct 167 ms 1280 KB Output is correct
37 Correct 734 ms 1220 KB Output is correct
38 Correct 275 ms 1280 KB Output is correct
39 Correct 135 ms 1152 KB Output is correct
40 Correct 367 ms 1108 KB Output is correct
41 Correct 40 ms 1272 KB Output is correct
42 Correct 81 ms 1280 KB Output is correct
43 Correct 58 ms 1024 KB Output is correct
44 Correct 31 ms 1280 KB Output is correct
45 Correct 36 ms 1280 KB Output is correct
46 Correct 32 ms 1280 KB Output is correct
47 Correct 43 ms 1280 KB Output is correct
48 Correct 40 ms 1280 KB Output is correct
49 Correct 608 ms 1152 KB Output is correct
50 Correct 1030 ms 1132 KB Output is correct
51 Correct 166 ms 1124 KB Output is correct
52 Correct 128 ms 1152 KB Output is correct
53 Correct 21 ms 1280 KB Output is correct
54 Correct 224 ms 1200 KB Output is correct
55 Correct 393 ms 1196 KB Output is correct
56 Correct 334 ms 1272 KB Output is correct
57 Correct 57 ms 1152 KB Output is correct
58 Correct 37 ms 1152 KB Output is correct
59 Correct 1314 ms 1432 KB Output is correct
60 Correct 1338 ms 1400 KB Output is correct
61 Correct 1371 ms 1528 KB Output is correct
62 Correct 96 ms 1152 KB Output is correct
63 Correct 123 ms 1164 KB Output is correct
64 Incorrect 10 ms 1152 KB 3rd lines differ - on the 1st token, expected: '1', found: '0'
65 Halted 0 ms 0 KB -