結果
問題 | No.2308 [Cherry 5th Tune B] もしかして、真? |
ユーザー | chro_96 |
提出日時 | 2023-05-19 22:48:07 |
言語 | C (gcc 12.3.0) |
結果 |
AC
|
実行時間 | 668 ms / 2,000 ms |
コード長 | 2,553 bytes |
コンパイル時間 | 1,991 ms |
コンパイル使用メモリ | 32,372 KB |
実行使用メモリ | 8,616 KB |
最終ジャッジ日時 | 2024-12-20 01:20:48 |
合計ジャッジ時間 | 23,383 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
8,504 KB |
testcase_01 | AC | 484 ms
8,580 KB |
testcase_02 | AC | 588 ms
8,448 KB |
testcase_03 | AC | 536 ms
8,436 KB |
testcase_04 | AC | 531 ms
8,580 KB |
testcase_05 | AC | 547 ms
8,448 KB |
testcase_06 | AC | 589 ms
8,544 KB |
testcase_07 | AC | 585 ms
8,412 KB |
testcase_08 | AC | 610 ms
8,536 KB |
testcase_09 | AC | 616 ms
8,556 KB |
testcase_10 | AC | 541 ms
8,416 KB |
testcase_11 | AC | 589 ms
8,404 KB |
testcase_12 | AC | 588 ms
8,440 KB |
testcase_13 | AC | 587 ms
8,616 KB |
testcase_14 | AC | 594 ms
8,452 KB |
testcase_15 | AC | 590 ms
8,528 KB |
testcase_16 | AC | 592 ms
8,392 KB |
testcase_17 | AC | 592 ms
8,416 KB |
testcase_18 | AC | 588 ms
8,432 KB |
testcase_19 | AC | 586 ms
8,456 KB |
testcase_20 | AC | 579 ms
8,396 KB |
testcase_21 | AC | 664 ms
8,456 KB |
testcase_22 | AC | 664 ms
8,388 KB |
testcase_23 | AC | 657 ms
8,448 KB |
testcase_24 | AC | 668 ms
8,404 KB |
testcase_25 | AC | 662 ms
8,520 KB |
testcase_26 | AC | 658 ms
8,432 KB |
testcase_27 | AC | 658 ms
8,416 KB |
testcase_28 | AC | 668 ms
8,608 KB |
testcase_29 | AC | 663 ms
8,388 KB |
testcase_30 | AC | 666 ms
8,404 KB |
testcase_31 | AC | 408 ms
8,420 KB |
testcase_32 | AC | 405 ms
8,404 KB |
testcase_33 | AC | 406 ms
8,452 KB |
testcase_34 | AC | 416 ms
8,580 KB |
testcase_35 | AC | 411 ms
8,540 KB |
testcase_36 | AC | 414 ms
8,484 KB |
testcase_37 | AC | 11 ms
8,584 KB |
testcase_38 | AC | 582 ms
8,388 KB |
ソースコード
#include <stdio.h> #include <string.h> typedef struct tree { int v; struct tree *p; } tree; tree *get_root (tree *t) { if (t == NULL || t->p == NULL) { return t; } t->p = get_root(t->p); return t->p; } void add_segt (int *t, int idx, int val, int size) { idx = idx+size-1; t[idx] += val; while (idx > 0) { idx = (idx-1)/2; t[idx] += val; } return; } int sum_segt_rec (int *t, int a, int b, int k, int l, int r) { int ans = 0; if (r <= a || b <= l) { return 0; } if (a <= l && r <= b) { return t[k]; } ans = sum_segt_rec(t, a, b, 2*k+1, l, (l+r)/2); ans += sum_segt_rec(t, a, b, 2*k+2, (l+r)/2, r); return ans; } int sum_segt (int *t, int a, int b, int size) { return sum_segt_rec(t, a, b, 0, 0, size); } int main () { int t = 0; int n = 0; char x[6] = ""; char y[199999][4] = {}; int s[199999] = {}; int res = 0; tree tr[200000] = {}; int segt[524287] = {}; res = scanf("%d", &t); while (t > 0) { int size = 1; tree *rt = NULL; res = scanf("%d", &n); for (int i = 0; i < n; i++) { res = scanf("%s", x); if (x[0] == 'T') { tr[i].v = 1; tr[i].p = NULL; } else { tr[i].v = 0; tr[i].p = NULL; } } for (int i = 0; i < n-1; i++) { res = scanf("%s", y[i]); } for (int i = 0; i < n-1; i++) { res = scanf("%d", s+i); } while (size <= n) { size <<= 1; } for (int i = 0; i < 2*size-1; i++) { segt[i] = 0; } for (int i = 0; i < n; i++) { add_segt(segt, i, 1, size); } for (int i = 0; i < n-1; i++) { int idx[2] = { 0, n }; tree *rt1 = NULL; tree *rt2 = NULL; while (idx[1]-idx[0] > 1) { int nxt = (idx[0]+idx[1])/2; if (sum_segt(segt, 0, nxt, size) < s[i]) { idx[0] = nxt; } else { idx[1] = nxt; } } rt1 = get_root(tr+idx[0]); rt2 = get_root(tr+idx[1]); if (strcmp(y[idx[0]], "and") == 0) { rt1->v = rt1->v*rt2->v; } else if (strcmp(y[idx[0]], "or") == 0) { rt1->v = rt1->v*rt2->v+((rt1->v)^(rt2->v)); } else if (strcmp(y[idx[0]], "imp") == 0) { rt1->v = (1-rt1->v)*rt2->v+((1-rt1->v)^(rt2->v)); } else { rt1->v = (rt1->v)^(rt2->v); } rt2->p = rt1; add_segt(segt, idx[0], -1, size); } rt = get_root(tr); if (rt->v > 0) { printf("True\n"); } else { printf("False\n"); } t--; } return 0; }