結果

問題 No.2735 Demarcation
ユーザー yosupotyosupot
提出日時 2024-04-19 22:54:29
言語 Rust
(1.77.0)
結果
TLE  
実行時間 -
コード長 2,188 bytes
コンパイル時間 7,221 ms
コンパイル使用メモリ 152,824 KB
実行使用メモリ 335,728 KB
最終ジャッジ日時 2024-04-19 22:54:49
合計ジャッジ時間 12,727 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
10,752 KB
testcase_01 AC 0 ms
5,248 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 0 ms
5,376 KB
testcase_04 AC 616 ms
335,728 KB
testcase_05 AC 59 ms
31,872 KB
testcase_06 AC 495 ms
271,932 KB
testcase_07 AC 583 ms
317,920 KB
testcase_08 AC 654 ms
308,300 KB
testcase_09 AC 215 ms
120,832 KB
testcase_10 AC 295 ms
168,064 KB
testcase_11 AC 113 ms
70,784 KB
testcase_12 AC 51 ms
23,936 KB
testcase_13 AC 100 ms
43,136 KB
testcase_14 AC 440 ms
233,984 KB
testcase_15 AC 76 ms
32,256 KB
testcase_16 AC 476 ms
274,304 KB
testcase_17 AC 362 ms
161,264 KB
testcase_18 AC 141 ms
72,576 KB
testcase_19 AC 556 ms
315,572 KB
testcase_20 AC 556 ms
294,176 KB
testcase_21 AC 414 ms
225,728 KB
testcase_22 AC 630 ms
325,832 KB
testcase_23 TLE -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused import: `std::collections::BTreeSet`
 --> main.rs:3:5
  |
3 | use std::collections::BTreeSet;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: 1 warning emitted

ソースコード

diff #

use core::cmp::{max, min};
use proconio::input;
use std::collections::BTreeSet;

fn main() {
    input! {
        n: i32,
        x: [i32; n],
        q: i32,
        ques: [(i32, i32, i64); q],
    }

    let mut count_same = vec![0; n as usize];
    for i in 0..(n - 1) {
        count_same[(i + 1) as usize] = count_same[i as usize]
            + if x[i as usize] == x[(i + 1) as usize] {
                1
            } else {
                0
            }
    }

    const MAX_K: i32 = 70;
    let mut range = vec![vec![n; (MAX_K + 1) as usize]; n as usize];
    let mut vis = vec![-1; (n + 1) as usize];
    for i in 0..n {
        let mut vis_count = 0;
        for j in (max(0, i - MAX_K + 1)..i + 1).rev() {
            if vis[x[j as usize] as usize] != i {
                vis_count += 1;
                vis[x[j as usize] as usize] = i;
            }
            range[i as usize][vis_count] = j;
        }
        for k in (vis_count as i32)..MAX_K + 1 {
            range[i as usize][k as usize] = 0;
        }
    }

    for (l, r, s) in ques {
        let l = l - 1;

        let dist = r - l;

        if dist <= 62 && 1i64 << (dist - 1) <= s {
            println!("-1");
            continue;
        }

        let same = count_same[(r - 1) as usize] - count_same[l as usize];

        if 61 <= same || s < (1i64 << same) {
            println!("0");
            continue;
        }

        const INF: i128 = 1i128 << 62;
        for k in 2..MAX_K {
            let mut dp = vec![0i128; (dist + 1) as usize];
            let mut dp_sum = vec![0i128; (dist + 1 + 1) as usize];
            dp[0] = 1;
            dp_sum[1] = 1;
            for i in l..r {
                dp[(i + 1 - l) as usize] = min(
                    INF,
                    dp_sum[(i + 1 - l) as usize]
                        - dp_sum[(max(l, range[i as usize][k as usize]) - l) as usize],
                );
                dp_sum[(i + 1 - l + 1) as usize] =
                    dp_sum[(i + 1 - l) as usize] + dp[(i + 1 - l) as usize];
            }
            if dp[dist as usize] > s as i128 {
                println!("{}", k - 1);
                break;
            }
        }
    }
}
0