結果
問題 | No.2735 Demarcation |
ユーザー | kusirakusira |
提出日時 | 2024-04-09 23:15:48 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,453 bytes |
コンパイル時間 | 303 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 261,304 KB |
最終ジャッジ日時 | 2024-10-11 11:44:08 |
合計ジャッジ時間 | 11,692 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
52,608 KB |
testcase_01 | AC | 43 ms
52,608 KB |
testcase_02 | AC | 42 ms
52,224 KB |
testcase_03 | AC | 43 ms
52,224 KB |
testcase_04 | AC | 350 ms
212,128 KB |
testcase_05 | AC | 218 ms
89,344 KB |
testcase_06 | AC | 381 ms
201,728 KB |
testcase_07 | AC | 616 ms
236,060 KB |
testcase_08 | WA | - |
testcase_09 | AC | 297 ms
128,748 KB |
testcase_10 | AC | 334 ms
165,628 KB |
testcase_11 | AC | 157 ms
109,568 KB |
testcase_12 | AC | 189 ms
84,736 KB |
testcase_13 | AC | 285 ms
95,488 KB |
testcase_14 | AC | 572 ms
204,376 KB |
testcase_15 | AC | 373 ms
89,344 KB |
testcase_16 | AC | 392 ms
202,484 KB |
testcase_17 | AC | 455 ms
154,776 KB |
testcase_18 | AC | 258 ms
109,568 KB |
testcase_19 | AC | 538 ms
235,560 KB |
testcase_20 | AC | 649 ms
226,664 KB |
testcase_21 | AC | 361 ms
197,820 KB |
testcase_22 | AC | 327 ms
241,972 KB |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | AC | 301 ms
190,424 KB |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
ソースコード
N = int(input()) X = list(map(int, input().split())) for i in range(N): X[i] -= 1 diff_sum = [0 for _ in range(N)] for i in range(N - 1): if X[i] != X[i + 1]: diff_sum[i + 1] = diff_sum[i] else: diff_sum[i + 1] = diff_sum[i] + 1 kinds = [0 for _ in range(N)] Q = int(input()) for _ in range(Q): l, r, S = map(int, input().split()) l -= 1 r -= 1 if r - l >= 90: diffs = diff_sum[r] - diff_sum[l] if diffs >= 60: print(0) else: if S >= (1 << diffs): print(1 << diffs) else: print(0) else: vec = [0 for _ in range(r - l + 1)] for j in range(l, r + 1): vec[j - l] = X[j] len_vec = len(vec) ans = [0 for _ in range(len_vec + 2)] ok = 0 ng = len_vec + 2 while ng - ok > 1: mid = (ok + ng) // 2 prev_idx = [-1 for _ in range(len_vec + 1)] now_kind = 0 left = 0 right = 0 while True: if now_kind <= mid: if right == len_vec: prev_idx[right] = left break else: prev_idx[right] = left if kinds[vec[right]] == 0: now_kind += 1 kinds[vec[right]] += 1 right += 1 else: kinds[vec[left]] -= 1 if kinds[vec[left]] == 0: now_kind -= 1 left += 1 dp = [0 for _ in range(len_vec + 1)] dp_sum = [0 for _ in range(len_vec + 1)] dp[0] = 1 dp_sum[0] = 1 infin = False for j in range(1, len_vec + 1): sum_val = dp_sum[j - 1] if prev_idx[j] > 0: sum_val -= dp_sum[prev_idx[j] - 1] if sum_val > S: infin = True break dp[j] = sum_val dp_sum[j] = dp[j] + dp_sum[j - 1] if infin: ng = mid else: ok = mid ans[mid] = dp[len_vec] for j in range(len_vec): kinds[vec[j]] = 0 if ok >= len_vec: print(-1) else: print(ok)