Submission #559107

# Submission time Handle Problem Language Result Execution time Memory
559107 2022-05-09T11:54:33 Z cadmiumsky Toy Train (IOI17_train) C++14
0 / 100
1341 ms 176584 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;

int cnt = 0;
void solve(uset& V) {
  if(V.size() == 0)
    return;
  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;
  };
  uset now;
  now = S;
  for(auto x : now)
    markall(x);
  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();
  }
  swap(S, notS);
  now = S;
  for(auto x : now)
    markall(x);
  for(auto x : S)
    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:22:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     for(int i = 0; i < g[x].size(); i++) {
      |                    ~~^~~~~~~~~~~~~
train.cpp:26:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     for(int i = 0; i < t[x].size(); i++) {
      |                    ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 2260 KB 3rd lines differ - on the 22nd token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Incorrect 1 ms 468 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 592 ms 88888 KB Output is correct
2 Correct 1002 ms 149652 KB Output is correct
3 Correct 1341 ms 176584 KB Output is correct
4 Correct 10 ms 2516 KB Output is correct
5 Incorrect 12 ms 2604 KB 3rd lines differ - on the 25th token, expected: '1', found: '0'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 1748 KB 3rd lines differ - on the 696th token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 2004 KB 3rd lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 2260 KB 3rd lines differ - on the 22nd token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -