답안 #1061248

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1061248 2024-08-16T07:28:36 Z vjudge1 장난감 기차 (IOI17_train) C++17
0 / 100
2000 ms 25816 KB
// #include "train.h"
#include<bits/stdc++.h>

using namespace std;

const int N = 5000 + 10;
vector<int> G[N];
bool R[N], seen[N][N];
int n;

bool dfs(int v, int s)
{
  seen[v][s] = true;
  if(R[v]) return 1;

  bool ok = 0;
  for(int u : G[v])
    {
      if(seen[u][s]) continue;
      ok |= dfs(u, s);
    }
  return ok;
}

vector<int> Arezou()
{
  vector<int> w(n);
  for(int s = 0; s < n; s++)
    w[s] = dfs(s, s);
  return w;
}

vector<int> Borzou()
{
  vector<int> w(n);
  return w;
}


vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v)
{
  n = a.size();
  for(int i = 0; i < u.size(); i ++)
    G[u[i]].push_back(v[i]);
  

  for(int i = 0; i < n; i ++)
    R[i] = r[i];
  
  vector<int> w(n);
  int c = count(a.begin(), a.end(), 1);

  if(c == a.size())
    return Arezou();
  if(c == 0)
    return Borzou();

  for(int i = 0; i < n; i++)
    {
      int s = i;
      while(true)
	{
	  // do I have a cycle
	  bool cycle = false;
	  for(int c : G[s])
	    if(c == s) cycle = true;

	  if(cycle)
	    {
	      if(G[s].size() == 1)
		{
		  w[i] = r[s];
		  break;
		}
	      
	      if(r[s])
		{
		  if(a[s] == 1)
		    {
		      w[i] = 1;
		      break;
		    }
		  s++;
		  continue;
		}

	      if(a[s] == 1)
		{
		  s++;
		  continue;
		}
	      else
		{
		  w[i] = 0;
		  break;
		}
	    }
	}
    }
  return w;
}

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:43:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |   for(int i = 0; i < u.size(); i ++)
      |                  ~~^~~~~~~~~~
train.cpp:53:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |   if(c == a.size())
      |      ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2062 ms 860 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2066 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 103 ms 25816 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 856 KB 3rd lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2037 ms 1112 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2062 ms 860 KB Time limit exceeded
2 Halted 0 ms 0 KB -