답안 #149358

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
149358 2019-09-01T06:19:31 Z 등수만큼 신재웅 생일빵 때림 (10대)(#3628, kjp4155, GodTe, JWoong148) Bulb Game (FXCUP4_bulb) C++17
0 / 100
2 ms 376 KB
#include "bulb.h"
#include "bits/stdc++.h"
using namespace std;

template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
template <class T>
ostream &operator<<(ostream &os, vector<T> V) {
  os << "[";
  for (auto x : V) os << x << ", ";
  return os << "]";
}
template <typename... Args>
void dbg(Args... args) {
  ((cerr << args << " "), ...);
  cerr << "\n";
}
void dfs(int c, vector<int> &L, vector<int> &R, vector<int> &cur, vector<int> &change) {
  if (L[c] == -1 || L[c] == -2) {
    cur[c] = -L[c];
  } else {
    dfs(L[c], L, R, cur, change);
    cur[c] = cur[L[c]];
  }
  if (R[c] == -1 || R[c] == -2) {
    change[c] = -R[c];
  } else {
    dfs(R[c], L, R, cur, change);
    change[c] = cur[R[c]];
  }
}
int FindWinner(int T, std::vector<int> L, std::vector<int> R) {
  int N = L.size();
  vector<int> cur(N, 0), change(N, 0);  // 1: R, 2: B
  dfs(0, L, R, cur, change);

  if (cur[0] == 2) return 0;

  vector<int> idx;
  int pv = 0;
  idx.push_back(pv);
  while (L[pv] >= 0) {
    idx.push_back(L[pv]);
    pv = L[pv];
  }
  int i = 0;
  for (; i < idx.size(); i++) {
    if (change[i] == 2) break;
  }
  if (i == idx.size()) return 1;
  for (int j = 0; j < i; j++) {
    int pv = R[j];
    int flag = true;
    while (pv >= 0) {
      if (change[pv] == 2) flag = false;
      pv = R[pv];
    }
    if (flag) return 1;
  }
  return 0;
}

Compilation message

bulb.cpp: In function 'int FindWinner(int, std::vector<int>, std::vector<int>)':
bulb.cpp:49:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (; i < idx.size(); i++) {
          ~~^~~~~~~~~~~~
bulb.cpp:52:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (i == idx.size()) return 1;
       ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 352 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -