답안 #70062

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
70062 2018-08-22T10:02:04 Z bnahmad15 장난감 기차 (IOI17_train) C++17
15 / 100
174 ms 2240 KB
#include "train.h"
#include <bits/stdc++.h>
using namespace std;

const int N = 5001;
int n,is[N],vis[N],own[N],to[N],self[N];
vector <int> g[N],S;

int dfs(int u){
	vis[u] = 1;
	S.push_back(u);
	int ret;
	if(own[u] == 0){
		ret = 1;
		for(int i = 0;i<g[u].size();i++){
			int v = g[u][i];
			if(vis[v] == 1){
				int flag = 0;
				for(int j = S.size()-1;j>=0;j--){
					if(is[S[j]] == 1){
						flag = 1;
						break;
					}
					if(S[j] == v)
						break;
				}
				ret = min(ret,flag);
			}else{
				ret = min(ret,dfs(v));
			}
		}
	}else{
		ret = 0;
		for(int i = 0;i<g[u].size();i++){
			int v = g[u][i];
			if(vis[v] == 1){
				int flag = 0;
				for(int j = S.size()-1;j>=0;j--){
					if(is[S[j]] == 1){
						flag = 1;
						break;
					}
					if(S[j] == v)
						break;
				}
				ret = max(ret,flag);
			}else{
				ret = max(ret,dfs(v));
			}
		}
	}
	vis[u] = 0;
	S.pop_back();
	return ret;
}
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {

	std::vector<int> res;
	n = a.size();
	for(int i = 0;i<n;i++){
		is[i] = self[i] = to[i] = 0;
	}
	for(int i = 0;i<u.size();i++){
		g[u[i]].push_back(v[i]);
		if(u[i] == v[i])
			self[u[i]] = 1;
		if(u[i] + 1 == v[i])
			to[u[i]] = 1;
	}
	for(int i = 0;i<n;i++)
		is[i] = r[i];
	for(int i = 0;i<n;i++)
		own[i] = a[i];
	if(n <= 15){
		int cnt = 0;
		for(int i = 0;i<n;i++){
			for(int j = 0;j<n;j++){
				vis[j] = 0;
			}
			cnt++;
			res.push_back(dfs(i));
		}
	}else{
		if(is[n-1] && self[n-1])
			res.push_back(1);
		else
			res.push_back(0);
		for(int i = n-2;i>=0;i--){
			if(own[i] == 0){
				int ret = 1;
				ret = min(ret,((!is[i] && self[i]) ? 0 : 1));
				ret = min(ret,((to[i]) ? res.back() : 1));
				res.push_back(ret);
			}else{
				int ret = 0;
				ret = max(ret,((is[i] && self[i]) ? 1 : 0));
				ret = max(ret,((to[i]) ? res.back() : 0));
				res.push_back(ret);				
			}
		}
		reverse(res.begin(),res.end());
	}
	return res;
}

Compilation message

train.cpp: In function 'int dfs(int)':
train.cpp:15:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0;i<g[u].size();i++){
                 ~^~~~~~~~~~~~
train.cpp:34:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0;i<g[u].size();i++){
                 ~^~~~~~~~~~~~
train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:63:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0;i<u.size();i++){
                ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 888 KB Output is correct
2 Correct 7 ms 996 KB Output is correct
3 Correct 7 ms 1252 KB Output is correct
4 Correct 7 ms 1308 KB Output is correct
5 Correct 7 ms 1388 KB Output is correct
6 Correct 9 ms 1600 KB Output is correct
7 Correct 9 ms 1600 KB Output is correct
8 Correct 9 ms 1748 KB Output is correct
9 Correct 10 ms 1840 KB Output is correct
10 Correct 11 ms 1892 KB Output is correct
11 Correct 7 ms 1892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1892 KB Output is correct
2 Correct 2 ms 1892 KB Output is correct
3 Correct 2 ms 1892 KB Output is correct
4 Correct 174 ms 1892 KB Output is correct
5 Correct 3 ms 1892 KB Output is correct
6 Correct 3 ms 1892 KB Output is correct
7 Correct 2 ms 1892 KB Output is correct
8 Correct 6 ms 1892 KB Output is correct
9 Correct 73 ms 1892 KB Output is correct
10 Correct 3 ms 1892 KB Output is correct
11 Correct 39 ms 1892 KB Output is correct
12 Correct 3 ms 1892 KB Output is correct
13 Correct 2 ms 1892 KB Output is correct
14 Correct 2 ms 1892 KB Output is correct
15 Correct 3 ms 1892 KB Output is correct
16 Correct 3 ms 1892 KB Output is correct
17 Correct 3 ms 1892 KB Output is correct
18 Correct 2 ms 1892 KB Output is correct
19 Correct 3 ms 1892 KB Output is correct
20 Correct 2 ms 1892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 2240 KB Output is correct
2 Correct 9 ms 2240 KB Output is correct
3 Correct 10 ms 2240 KB Output is correct
4 Incorrect 12 ms 2240 KB 3rd lines differ - on the 1st token, expected: '1', found: '0'
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 2240 KB 3rd lines differ - on the 696th token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 2240 KB 3rd lines differ - on the 2nd token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 888 KB Output is correct
2 Correct 7 ms 996 KB Output is correct
3 Correct 7 ms 1252 KB Output is correct
4 Correct 7 ms 1308 KB Output is correct
5 Correct 7 ms 1388 KB Output is correct
6 Correct 9 ms 1600 KB Output is correct
7 Correct 9 ms 1600 KB Output is correct
8 Correct 9 ms 1748 KB Output is correct
9 Correct 10 ms 1840 KB Output is correct
10 Correct 11 ms 1892 KB Output is correct
11 Correct 7 ms 1892 KB Output is correct
12 Correct 3 ms 1892 KB Output is correct
13 Correct 2 ms 1892 KB Output is correct
14 Correct 2 ms 1892 KB Output is correct
15 Correct 174 ms 1892 KB Output is correct
16 Correct 3 ms 1892 KB Output is correct
17 Correct 3 ms 1892 KB Output is correct
18 Correct 2 ms 1892 KB Output is correct
19 Correct 6 ms 1892 KB Output is correct
20 Correct 73 ms 1892 KB Output is correct
21 Correct 3 ms 1892 KB Output is correct
22 Correct 39 ms 1892 KB Output is correct
23 Correct 3 ms 1892 KB Output is correct
24 Correct 2 ms 1892 KB Output is correct
25 Correct 2 ms 1892 KB Output is correct
26 Correct 3 ms 1892 KB Output is correct
27 Correct 3 ms 1892 KB Output is correct
28 Correct 3 ms 1892 KB Output is correct
29 Correct 2 ms 1892 KB Output is correct
30 Correct 3 ms 1892 KB Output is correct
31 Correct 2 ms 1892 KB Output is correct
32 Correct 14 ms 2240 KB Output is correct
33 Correct 9 ms 2240 KB Output is correct
34 Correct 10 ms 2240 KB Output is correct
35 Incorrect 12 ms 2240 KB 3rd lines differ - on the 1st token, expected: '1', found: '0'
36 Halted 0 ms 0 KB -