結果
問題 | No.1355 AND OR GAME |
ユーザー | LyricalMaestro |
提出日時 | 2024-12-06 01:33:55 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 447 ms / 2,000 ms |
コード長 | 3,233 bytes |
コンパイル時間 | 343 ms |
コンパイル使用メモリ | 82,560 KB |
実行使用メモリ | 226,724 KB |
最終ジャッジ日時 | 2024-12-06 01:34:26 |
合計ジャッジ時間 | 26,652 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
52,224 KB |
testcase_01 | AC | 42 ms
52,352 KB |
testcase_02 | AC | 55 ms
64,512 KB |
testcase_03 | AC | 57 ms
64,768 KB |
testcase_04 | AC | 55 ms
64,768 KB |
testcase_05 | AC | 44 ms
57,600 KB |
testcase_06 | AC | 56 ms
64,512 KB |
testcase_07 | AC | 58 ms
64,512 KB |
testcase_08 | AC | 58 ms
64,640 KB |
testcase_09 | AC | 46 ms
59,648 KB |
testcase_10 | AC | 41 ms
51,968 KB |
testcase_11 | AC | 41 ms
52,352 KB |
testcase_12 | AC | 40 ms
52,224 KB |
testcase_13 | AC | 41 ms
52,224 KB |
testcase_14 | AC | 41 ms
52,224 KB |
testcase_15 | AC | 43 ms
52,480 KB |
testcase_16 | AC | 41 ms
52,352 KB |
testcase_17 | AC | 40 ms
52,096 KB |
testcase_18 | AC | 41 ms
52,480 KB |
testcase_19 | AC | 40 ms
52,224 KB |
testcase_20 | AC | 39 ms
52,864 KB |
testcase_21 | AC | 40 ms
52,224 KB |
testcase_22 | AC | 40 ms
52,224 KB |
testcase_23 | AC | 41 ms
52,096 KB |
testcase_24 | AC | 40 ms
52,352 KB |
testcase_25 | AC | 40 ms
52,480 KB |
testcase_26 | AC | 42 ms
52,608 KB |
testcase_27 | AC | 41 ms
52,352 KB |
testcase_28 | AC | 39 ms
52,224 KB |
testcase_29 | AC | 42 ms
52,608 KB |
testcase_30 | AC | 41 ms
52,096 KB |
testcase_31 | AC | 41 ms
52,096 KB |
testcase_32 | AC | 39 ms
52,224 KB |
testcase_33 | AC | 41 ms
52,096 KB |
testcase_34 | AC | 82 ms
81,408 KB |
testcase_35 | AC | 356 ms
226,592 KB |
testcase_36 | AC | 301 ms
212,348 KB |
testcase_37 | AC | 40 ms
52,352 KB |
testcase_38 | AC | 321 ms
226,464 KB |
testcase_39 | AC | 153 ms
121,104 KB |
testcase_40 | AC | 181 ms
137,372 KB |
testcase_41 | AC | 317 ms
226,336 KB |
testcase_42 | AC | 323 ms
226,572 KB |
testcase_43 | AC | 228 ms
160,660 KB |
testcase_44 | AC | 96 ms
91,348 KB |
testcase_45 | AC | 320 ms
226,460 KB |
testcase_46 | AC | 159 ms
124,408 KB |
testcase_47 | AC | 340 ms
226,468 KB |
testcase_48 | AC | 250 ms
178,820 KB |
testcase_49 | AC | 321 ms
226,208 KB |
testcase_50 | AC | 39 ms
51,968 KB |
testcase_51 | AC | 184 ms
137,404 KB |
testcase_52 | AC | 302 ms
209,572 KB |
testcase_53 | AC | 211 ms
150,796 KB |
testcase_54 | AC | 322 ms
226,596 KB |
testcase_55 | AC | 338 ms
211,780 KB |
testcase_56 | AC | 296 ms
211,876 KB |
testcase_57 | AC | 240 ms
170,620 KB |
testcase_58 | AC | 104 ms
92,368 KB |
testcase_59 | AC | 39 ms
52,352 KB |
testcase_60 | AC | 261 ms
170,188 KB |
testcase_61 | AC | 40 ms
52,224 KB |
testcase_62 | AC | 176 ms
131,716 KB |
testcase_63 | AC | 324 ms
226,212 KB |
testcase_64 | AC | 304 ms
211,880 KB |
testcase_65 | AC | 60 ms
65,280 KB |
testcase_66 | AC | 135 ms
111,224 KB |
testcase_67 | AC | 141 ms
113,412 KB |
testcase_68 | AC | 140 ms
113,696 KB |
testcase_69 | AC | 39 ms
52,352 KB |
testcase_70 | AC | 157 ms
124,884 KB |
testcase_71 | AC | 317 ms
226,724 KB |
testcase_72 | AC | 324 ms
226,332 KB |
testcase_73 | AC | 308 ms
226,464 KB |
testcase_74 | AC | 320 ms
226,596 KB |
testcase_75 | AC | 318 ms
226,332 KB |
testcase_76 | AC | 326 ms
226,460 KB |
testcase_77 | AC | 330 ms
226,204 KB |
testcase_78 | AC | 40 ms
52,352 KB |
testcase_79 | AC | 39 ms
51,968 KB |
testcase_80 | AC | 331 ms
226,464 KB |
testcase_81 | AC | 317 ms
226,472 KB |
testcase_82 | AC | 341 ms
226,464 KB |
testcase_83 | AC | 299 ms
211,896 KB |
testcase_84 | AC | 198 ms
113,916 KB |
testcase_85 | AC | 335 ms
164,960 KB |
testcase_86 | AC | 266 ms
129,676 KB |
testcase_87 | AC | 222 ms
123,784 KB |
testcase_88 | AC | 102 ms
80,384 KB |
testcase_89 | AC | 97 ms
78,976 KB |
testcase_90 | AC | 422 ms
188,900 KB |
testcase_91 | AC | 127 ms
89,344 KB |
testcase_92 | AC | 102 ms
81,024 KB |
testcase_93 | AC | 401 ms
181,128 KB |
testcase_94 | AC | 261 ms
137,300 KB |
testcase_95 | AC | 243 ms
120,100 KB |
testcase_96 | AC | 188 ms
109,428 KB |
testcase_97 | AC | 112 ms
80,768 KB |
testcase_98 | AC | 447 ms
212,080 KB |
ソースコード
## https://yukicoder.me/problems/no/1355 def calc_bit(X, max_k): array = [0] * max_k for i in range(max_k): array[i] = X % 2 X //= 2 return array def main(): N, X, Y = map(int, input().split()) A = list(map(int, input().split())) max_value = max(X, Y, max(A)) k = 0 while (1 << k) < max_value: k += 1 max_k = k + 1 x_bit = calc_bit(X, max_k) y_bit = calc_bit(Y, max_k) a_bits = [] for a in A: a_bit = calc_bit(a, max_k) a_bits.append(a_bit) current_bit = y_bit answer_p = [] same_flg = False for i in reversed(range(N)): a_bit = a_bits[i] # 一致している? is_ok = True for k in range(max_k): if current_bit[k] != -1 and current_bit[k] != a_bit[k]: is_ok = False break if is_ok: answer_p.append(3) same_flg = True break # 包含している?(X and A[i] = currentとなりえる?) is_ok2 = True for k in range(max_k): if current_bit[k] != -1: if current_bit[k] == 1 and a_bit[k] == 0: is_ok2 = False break # 包含されている?(X or A[i] = currentとなりえる?) is_ok3 = True for k in range(max_k): if current_bit[k] != -1: if current_bit[k] == 0 and a_bit[k] == 1: is_ok3 = False break if (not is_ok2) and (not is_ok3): print(-1) return elif is_ok2: # X and A[i] = currentは成り立つ for k in range(max_k): if current_bit[k] == -1: current_bit[k] = -1 else: if a_bit[k] == 1: current_bit[k] = current_bit[k] else: current_bit[k] = -1 answer_p.append(1) elif is_ok3: # X or A[i] = currentは成り立つ for k in range(max_k): if current_bit[k] == -1: current_bit[k] = -1 else: if a_bit[k] == 1: current_bit[k] = -1 else: current_bit[k] = current_bit[k] answer_p.append(2) if same_flg: for _ in range(len(answer_p), N): answer_p.append(3) answer_p.reverse() print(" ".join(map(str, answer_p))) else: # 一致している? is_ok = True for k in range(max_k): if current_bit[k] != -1 and current_bit[k] != x_bit[k]: is_ok = False break if not is_ok: print(-1) return else: answer_p.reverse() print(" ".join(map(str, answer_p))) # 剣山 # x = X # for i in range(N): # x = x & A[i] # elif answer_p[i] == 2: # x = x | A[i] # else: # x = A[i] # print(Y, x) if __name__ == "__main__": main()