답안 #559103

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
559103 2022-05-09T11:35:13 Z cadmiumsky 장난감 기차 (IOI17_train) C++14
0 / 100
12 ms 4820 KB
#include "train.h"
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using uset = unordered_set<int>;

const int nmax = 5e3 + 5;
vector<int> g[nmax], t[nmax];
vector<int> own, charge, rez, degree;

int n, m;

void solve(uset V) {
  uset S;
  for(auto x : V) {
    if(charge[x])
      S.insert(x);
    for(int i = 0; i < g[x].size(); i++) {
      if(V.count(g[x][i]) == 0)
        swap(g[x][i], g[x].back()), g[x].pop_back();
    }
    for(int i = 0; i < t[x].size(); i++) {
      if(V.count(t[x][i]) == 0)
        swap(t[x][i], t[x].back()), t[x].pop_back();
    }
  }
  if(S.size() == 0) {
    for(auto x : V)
      rez[x] = 0;
    return;
  }
  for(auto x : V) {
    if(charge[x])
      degree[x] = 0;
    if(own[x] == 1)
      degree[x] = 1;
    else
      degree[x] = g[x].size();
  }
  function<void(int)> markall = [&](int elem) {
    for(auto x : t[elem]) {
      degree[x]--;
      if(degree[x] == 0)
        S.insert(x),
        markall(x);
    }
    return;
  };
  markall(*S.begin());
  if(S.size() == V.size()) {
    for(auto x : V)
      rez[x] = 1;
    return;
  }
  uset notS;
  for(auto x : V)
    if(S.count(x) == 0)
      notS.insert(x);
  for(auto x : V) {
    if(notS.count(x) == 1)
      degree[x] = 0;
    if(own[x] == 0)
      degree[x] = 1;
    else
      degree[x] = g[x].size();
  }
  markall(*notS.begin());
  for(auto x : notS)
    rez[x] = 0, // formality
    V.erase(x);
  solve(V);
}

std::vector<int> who_wins(std::vector<int> A, std::vector<int> R, std::vector<int> U, std::vector<int> V) {
	own = move(A);
	charge = move(R);
  n = own.size();
  m = U.size();
  degree.resize(n, 0);
  rez.resize(n, 0);
  for(int i = 0; i < m; i++)
    g[U[i]].push_back(V[i]),
    t[V[i]].push_back(U[i]);
  uset Vertex;
  for(int i = 0; i < n; i++)
    Vertex.insert(i);
  solve(Vertex);
  return rez;
}

Compilation message

train.cpp: In function 'void solve(uset)':
train.cpp:19:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     for(int i = 0; i < g[x].size(); i++) {
      |                    ~~^~~~~~~~~~~~~
train.cpp:23:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     for(int i = 0; i < t[x].size(); i++) {
      |                    ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 1876 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 800 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 3156 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 2220 KB 3rd lines differ - on the 21st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 2476 KB Output is correct
2 Correct 10 ms 2388 KB Output is correct
3 Runtime error 12 ms 4820 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 1876 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -