답안 #295773

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
295773 2020-09-09T22:59:06 Z DanerZein 장난감 기차 (IOI17_train) C++14
0 / 100
10 ms 1536 KB
#include "train.h"
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
vector<vi> G;
bitset<5010> ab,cs;
int vis[5010];
vi res;
bool dfs(int u){
  //cout<<u<<endl;
  vis[u]=2;
  if(ab[u]==1){
    int x=-1;
    for(auto &v:G[u]){
      if(v==u and cs[v]==1){
	res[u]=1;
	return 1;
      }
      else{
	if(v!=u) x=v;
      }
    }
    if(x!=-1 and vis[x]==-1) return res[u]=dfs(x);
    return 0;
  }
  else{
    int x=-1;
    for(auto &v:G[u]){
      if(v==u and cs[v]==0){
	res[u]=0;
	return 0;
      }
      else{
	if(v!=u) x=v;
      }
    }
    if(x!=-1 and vis[x]==-1) return res[u]=dfs(x);
    return 1;
  }
}
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
  for(int i=0;i<a.size();i++){
    ab[i]=a[i];
    cs[i]=r[i];
  }
  int n=a.size();
  G.resize(n+1);
  res.resize(n);
  for(int i=0;i<u.size();i++){
    int x=u[i],y=v[i];
    G[x].push_back(y);
    G[y].push_back(x);
  }
  memset(vis,-1,sizeof vis);
  for(int i=0;i<a.size();i++){
    if(vis[i]==-1){
      dfs(i);
    }
  }
  return res;
}

Compilation message

train.cpp: In function 'bool dfs(int)':
train.cpp:23:43: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   23 |     if(x!=-1 and vis[x]==-1) return res[u]=dfs(x);
train.cpp:37:43: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   37 |     if(x!=-1 and vis[x]==-1) return res[u]=dfs(x);
train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:42:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |   for(int i=0;i<a.size();i++){
      |               ~^~~~~~~~~
train.cpp:49:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |   for(int i=0;i<u.size();i++){
      |               ~^~~~~~~~~
train.cpp:55:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |   for(int i=0;i<a.size();i++){
      |               ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 896 KB 3rd lines differ - on the 7th token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 384 KB 3rd lines differ - on the 2nd token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 1536 KB Output is correct
2 Correct 8 ms 1536 KB Output is correct
3 Correct 9 ms 1408 KB Output is correct
4 Incorrect 10 ms 1536 KB 3rd lines differ - on the 1st token, expected: '1', found: '0'
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 1280 KB 3rd lines differ - on the 97th token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 1408 KB 3rd lines differ - on the 2nd token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 896 KB 3rd lines differ - on the 7th token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -