提出 #42721642


ソースコード 拡げる

/*+Rainybunny+*/

#include <bits/stdc++.h>

#define rep(i, l, r) for (int i = l, rep##i = r; i <= rep##i; ++i)
#define per(i, r, l) for (int i = r, per##i = l; i >= per##i; --i)

const int MAXN = 1e3;
int n, k, fa[MAXN + 5], a[MAXN + 5], lak[MAXN + 5], req[MAXN + 5];
std::bitset<MAXN + 5> ocr[MAXN + 5];
std::vector<int> adj[MAXN + 5];

inline bool solve(const int u) {
    ocr[u].reset(), lak[u] = 0;
    if (a[u] == -1) ++lak[u];
    else ocr[u][a[u]] = true;
    for (int v: adj[u]) {
        if (solve(v)) return true;
        ocr[u] |= ocr[v], lak[u] += lak[v];
    }
    if (!ocr[u][k]) {
        int cnt = 0;
        rep (i, 0, k - 1) cnt += !ocr[u][i];
        if (cnt <= lak[u]) return ++req[lak[u]], true;
    }
    return false;
}

int main() {
    int T; scanf("%d", &T);
    while (T--) {
        scanf("%d %d", &n, &k);
        rep (i, 2, n) scanf("%d", &fa[i]);
        rep (i, 1, n) scanf("%d", &a[i]);

        memset(req, 0, n + 1 << 2);
        rep (i, 1, n) adj[i].clear();
        rep (i, 2, n) adj[fa[i]].push_back(i);
        solve(1);

        if (req[0] || req[1]) { puts("Alice"); goto FIN; }
        puts("Bob");
        FIN: ;
    }
    return 0;
}

提出情報

提出日時
問題 C - Mex Game on Tree
ユーザ Rainybunny
言語 C++ (GCC 9.2.1)
得点 0
コード長 1224 Byte
結果 WA
実行時間 8 ms
メモリ 3824 KiB

コンパイルエラー

./Main.cpp: In function ‘int main()’:
./Main.cpp:36:26: warning: suggest parentheses around ‘+’ inside ‘<<’ [-Wparentheses]
   36 |         memset(req, 0, n + 1 << 2);
      |                        ~~^~~
./Main.cpp:30:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   30 |     int T; scanf("%d", &T);
      |            ~~~~~^~~~~~~~~~
./Main.cpp:32:14: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   32 |         scanf("%d %d", &n, &k);
      |         ~~~~~^~~~~~~~~~~~~~~~~
./Main.cpp:33:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   33 |         rep (i, 2, n) scanf("%d", &fa[i]);
      |                       ~~~~~^~~~~~~~~~~~~~
./Main.cpp:34:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   34 |         rep (i, 1, n) scanf("%d", &a[i]);
      |                       ~~~~~^~~~~~~~~~~~~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 0 / 500
結果
AC × 1
AC × 7
WA × 5
セット名 テストケース
Sample 00_sample_01.txt
All 00_sample_01.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 02_handmade_01.txt, 02_handmade_02.txt
ケース名 結果 実行時間 メモリ
00_sample_01.txt AC 1 ms 3680 KiB
01_test_01.txt AC 8 ms 3816 KiB
01_test_02.txt WA 5 ms 3824 KiB
01_test_03.txt AC 7 ms 3824 KiB
01_test_04.txt WA 3 ms 3668 KiB
01_test_05.txt WA 4 ms 3540 KiB
01_test_06.txt WA 3 ms 3660 KiB
01_test_07.txt WA 3 ms 3680 KiB
01_test_08.txt AC 7 ms 3652 KiB
01_test_09.txt AC 5 ms 3660 KiB
02_handmade_01.txt AC 6 ms 3756 KiB
02_handmade_02.txt AC 8 ms 3752 KiB