結果
問題 | No.2308 [Cherry 5th Tune B] もしかして、真? |
ユーザー | 👑 chro_96 |
提出日時 | 2023-05-19 22:48:07 |
言語 | C (gcc 12.3.0) |
結果 |
AC
|
実行時間 | 653 ms / 2,000 ms |
コード長 | 2,553 bytes |
コンパイル時間 | 1,612 ms |
コンパイル使用メモリ | 31,284 KB |
実行使用メモリ | 8,576 KB |
最終ジャッジ日時 | 2023-08-23 00:51:31 |
合計ジャッジ時間 | 23,997 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
8,560 KB |
testcase_01 | AC | 464 ms
8,556 KB |
testcase_02 | AC | 573 ms
8,404 KB |
testcase_03 | AC | 514 ms
8,416 KB |
testcase_04 | AC | 518 ms
8,452 KB |
testcase_05 | AC | 536 ms
8,564 KB |
testcase_06 | AC | 568 ms
8,564 KB |
testcase_07 | AC | 570 ms
8,416 KB |
testcase_08 | AC | 589 ms
8,576 KB |
testcase_09 | AC | 596 ms
8,448 KB |
testcase_10 | AC | 527 ms
8,484 KB |
testcase_11 | AC | 569 ms
8,440 KB |
testcase_12 | AC | 571 ms
8,440 KB |
testcase_13 | AC | 568 ms
8,416 KB |
testcase_14 | AC | 570 ms
8,416 KB |
testcase_15 | AC | 573 ms
8,572 KB |
testcase_16 | AC | 566 ms
8,412 KB |
testcase_17 | AC | 570 ms
8,460 KB |
testcase_18 | AC | 568 ms
8,512 KB |
testcase_19 | AC | 569 ms
8,568 KB |
testcase_20 | AC | 571 ms
8,464 KB |
testcase_21 | AC | 647 ms
8,552 KB |
testcase_22 | AC | 653 ms
8,572 KB |
testcase_23 | AC | 648 ms
8,512 KB |
testcase_24 | AC | 647 ms
8,452 KB |
testcase_25 | AC | 648 ms
8,544 KB |
testcase_26 | AC | 645 ms
8,508 KB |
testcase_27 | AC | 646 ms
8,568 KB |
testcase_28 | AC | 651 ms
8,452 KB |
testcase_29 | AC | 651 ms
8,464 KB |
testcase_30 | AC | 641 ms
8,516 KB |
testcase_31 | AC | 396 ms
8,544 KB |
testcase_32 | AC | 396 ms
8,440 KB |
testcase_33 | AC | 398 ms
8,456 KB |
testcase_34 | AC | 403 ms
8,452 KB |
testcase_35 | AC | 402 ms
8,412 KB |
testcase_36 | AC | 401 ms
8,568 KB |
testcase_37 | AC | 10 ms
8,556 KB |
testcase_38 | AC | 566 ms
8,544 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; }