結果
問題 | No.2735 Demarcation |
ユーザー | kusirakusira |
提出日時 | 2024-04-09 23:16:57 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 562 ms / 1,500 ms |
コード長 | 2,444 bytes |
コンパイル時間 | 316 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 261,316 KB |
最終ジャッジ日時 | 2024-10-11 11:44:33 |
合計ジャッジ時間 | 10,897 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
52,864 KB |
testcase_01 | AC | 38 ms
52,608 KB |
testcase_02 | AC | 37 ms
52,608 KB |
testcase_03 | AC | 38 ms
52,736 KB |
testcase_04 | AC | 287 ms
212,380 KB |
testcase_05 | AC | 200 ms
89,472 KB |
testcase_06 | AC | 309 ms
201,988 KB |
testcase_07 | AC | 530 ms
235,880 KB |
testcase_08 | AC | 459 ms
229,504 KB |
testcase_09 | AC | 278 ms
128,896 KB |
testcase_10 | AC | 311 ms
165,628 KB |
testcase_11 | AC | 140 ms
109,440 KB |
testcase_12 | AC | 166 ms
84,992 KB |
testcase_13 | AC | 275 ms
95,900 KB |
testcase_14 | AC | 523 ms
204,868 KB |
testcase_15 | AC | 355 ms
89,344 KB |
testcase_16 | AC | 343 ms
202,744 KB |
testcase_17 | AC | 416 ms
154,508 KB |
testcase_18 | AC | 240 ms
109,820 KB |
testcase_19 | AC | 476 ms
235,808 KB |
testcase_20 | AC | 562 ms
226,160 KB |
testcase_21 | AC | 306 ms
197,924 KB |
testcase_22 | AC | 280 ms
242,296 KB |
testcase_23 | AC | 157 ms
112,780 KB |
testcase_24 | AC | 206 ms
164,324 KB |
testcase_25 | AC | 250 ms
190,428 KB |
testcase_26 | AC | 223 ms
177,596 KB |
testcase_27 | AC | 259 ms
185,336 KB |
testcase_28 | AC | 360 ms
260,660 KB |
testcase_29 | AC | 361 ms
261,316 KB |
ソースコード
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) 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)