답안 #150203

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
150203 2019-09-01T07:53:35 Z JeffreyHo(#3776, JeffreyHo) Bulb Game (FXCUP4_bulb) C++17
0 / 100
1000 ms 376 KB
#include "bulb.h"
using namespace std;

int l[300005], r[300005], c[300005], d[300005], e[300005], f[300005], o;

int t[600005], z;

int que(int l, int r) {
    int z = 890328;
    for (l += o, r += o; l < r; l >>= 1, r >>= 1) {
        if (l & 1) z = min(z, t[l++]);
        if (r & 1) z = min(z, t[--r]);
    }
    return z;
}

void dfs(int x) {
    d[x] = o;
    if (l[x] >= 0) c[l[x]] = c[x], dfs(l[x]);
    if (l[x] == -2) f[o++] = c[x];
    if (r[x] >= 0) c[r[x]] = c[x] + 1, dfs(r[x]);
    if (r[x] == -2) f[o++] = c[x] + 1;
    e[x] = o;
}

void dfs2(int x) {
    if (que(0, d[x]) >= 2 && que(d[x], e[x]) >= 3 && que(e[x], o) >= 2) z = 1;
    if (l[x] >= 0) dfs2(l[x]);
    if (r[x] >= 0) dfs2(r[x]);
}

int FindWinner(int k, std::vector<int> L, std::vector<int> R) {
    if (k == 1) while (1);
	int n = (int)L.size();
    for (int i = 0; i < n; i++) l[i] = L[i], r[i] = R[i];
    dfs(0);
    //for (int i = 0; i < n; i++) printf("%d %d %d\n", c[i], d[i], e[i]);
    for (int i = 0; i < o; i++) t[i + o] = f[i];
    for (int i = o - 1; i > 0; i--) t[i] = min(t[i << 1], t[i << 1 | 1]);
    //for (int i = 0; i < o + o; i++) printf("%d ", t[i]);
    //printf("%d\n", que(0, 2));
    dfs2(0);
	return z;
}

Compilation message

bulb.cpp: In function 'int FindWinner(int, std::vector<int>, std::vector<int>)':
bulb.cpp:33:17: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
     if (k == 1) while (1);
                 ^~~~~
bulb.cpp:34:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
  int n = (int)L.size();
  ^~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1032 ms 376 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1024 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1024 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -