답안 #294196

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
294196 2020-09-08T16:56:49 Z ASDF123 장난감 기차 (IOI17_train) C++14
0 / 100
2000 ms 3072 KB
#include "train.h"
#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];
  
  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]);
    }
  }
  
  void solve(vector <int> &ans) {
    vector <bool> used(MAXN, false);
    vector <int> ends;
    for (int i = 0; i < m; i++) {
      if (u[i] == v[i]) {
        ends.push_back(u[i]);
      }
    }
    for (int x : ends) {
      vector <int> path = {};
      int answer = r[x];
      ans[x] = answer;
      if (szof(rg[x]) == 2) {
        int v =(rg[x][0] == x ? rg[x][1] : rg[x][0]);
        while(1) {
          ans[v] = answer;
          if (szof(rg[v]) == 0) {
            break;
          }
          assert(v != rg[v][0]);
          v = rg[v][0];
        }
      }
    }
  }
};

vi who_wins(vi a, vi r, vi u, vi v) {
	vi res(a.size(), -1);
  LineSolve subtask1(a, r, u, v);
  subtask1.solve(res);
  return res;
}


//signed main() {
  //int n, m;
  //cin >> n >> m;
  //vector <int> a(n), r(n);
  //vector <int> u(m), v(m);
  //for (int i = 0; i < n; i++) {
    //cin >> a[i];
  //}
  //for (int i = 0; i < n; i++) {
    //cin >> r[i];
  //}
  //for (int i = 0; i < m; i++) {
    //cin >> u[i];
  //}
  //for (int i = 0; i < m; i++) {
    //cin >> v[i];
  //}
  //vector <int> ans = who_wins(a, r, u, v);
  //for (int i = 0; i < n; i++) {
    //cout << i << ": " << ans[i] << endl;
  //}
//}
/*
7 7
0 1 0 1 0 1 0
1 0 0 0 1 0 1
0 1 2 3 4 5 6
0 2 3 4 4 6 6
*/
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 2432 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2065 ms 512 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2067 ms 2048 KB Time limit exceeded
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 Incorrect 10 ms 1920 KB 3rd lines differ - on the 1st token, expected: '1', found: '-1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 2432 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -