답안 #296882

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
296882 2020-09-11T03:39:13 Z ASDF123 장난감 기차 (IOI17_train) C++17
5 / 100
12 ms 3712 KB
#include "train.h"
//#include "grader.cpp"
#include <bits/stdc++.h>
#define fr first
#define sc second
#define pii pair<int, int>
#define szof(s) (int)s.size()
#define all(s) s.begin(), s.end()
 
using namespace std;
 
typedef vector<int> vi;
 
const int MAXN = 5001;
 
struct LineSolve {
  vi a, r, u, v;
  int n, m;
  vector <int> g[MAXN];
  vector <int> rg[MAXN];
  
  bool need() {
    bool ans = 1;
    for (int i = 0; i < szof(u); i++) {
      ans &= (u[i] == v[i] || u[i] + 1 == v[i]);
    }
    return ans;
  }
  
  LineSolve (vi A, vi R, vi U, vi V) {
    a = A;
    r = R;
    u = U;
    v = V;
    n = szof(a);
    m = szof(u);
    for (int i = 0; i < m; i++) {
      g[u[i]].push_back(v[i]);
      rg[v[i]].push_back(u[i]);
    }
  }
  int calc(int pos) {
    int v = pos, can = n;
    while (1) {
      if (r[v]) {
        can = n;
      }
      if (!can) {
        return 0;
      }
      if (szof(g[v]) == 1) {
        if (g[v][0] == v) {
          if (r[v]) {
            return 1;
          } else {
            return 0;
          }
        } else {
          v = g[v][0];
          can--;
          continue;
        }
      }
      else { // 2 types of edges
        if (a[v]) { // Arezou
          if (r[v]) {
            return 1;
          }
          else {
            v = (g[v][0] == v ? g[v][1] : g[v][0]);
            can--;
            continue;
          }
        } else { // Borzou
          if (r[v] == 0) {
            return 0;
          }
          else {
            v = (g[v][0] == v ? g[v][1] : g[v][0]);
            can--;
            continue;
          }
        } 
      }
    }
  }
  void solve(vector <int> &ans) {
    for (int i = 0; i < n; i++) {
      ans[i] = calc(i);
    }
  }
};
 
vi who_wins(vi a, vi r, vi u, vi v) {
  vi res(a.size(), -1);
  LineSolve subtask1(a, r, u, v);
  if (subtask1.need()) {
    subtask1.solve(res);
  } else {
    assert(false);
  }
  return res;
}
 
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1280 KB Output is correct
2 Correct 7 ms 1280 KB Output is correct
3 Correct 6 ms 1408 KB Output is correct
4 Correct 6 ms 1280 KB Output is correct
5 Correct 6 ms 1280 KB Output is correct
6 Correct 6 ms 1280 KB Output is correct
7 Correct 6 ms 1280 KB Output is correct
8 Correct 6 ms 1280 KB Output is correct
9 Correct 6 ms 1280 KB Output is correct
10 Correct 6 ms 1408 KB Output is correct
11 Correct 5 ms 1280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 896 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 11 ms 3712 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 10 ms 3072 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 12 ms 3584 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1280 KB Output is correct
2 Correct 7 ms 1280 KB Output is correct
3 Correct 6 ms 1408 KB Output is correct
4 Correct 6 ms 1280 KB Output is correct
5 Correct 6 ms 1280 KB Output is correct
6 Correct 6 ms 1280 KB Output is correct
7 Correct 6 ms 1280 KB Output is correct
8 Correct 6 ms 1280 KB Output is correct
9 Correct 6 ms 1280 KB Output is correct
10 Correct 6 ms 1408 KB Output is correct
11 Correct 5 ms 1280 KB Output is correct
12 Runtime error 2 ms 896 KB Execution killed with signal 11
13 Halted 0 ms 0 KB -