結果

問題 No.1977 Extracting at Constant Intervals
ユーザー akakimidoriakakimidori
提出日時 2022-06-10 23:16:14
言語 Rust
(1.77.0)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 2,627 bytes
コンパイル時間 945 ms
コンパイル使用メモリ 173,376 KB
実行使用メモリ 7,168 KB
最終ジャッジ日時 2024-04-17 15:40:52
合計ジャッジ時間 1,994 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 0 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 9 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 9 ms
6,944 KB
testcase_06 AC 5 ms
6,940 KB
testcase_07 AC 7 ms
6,944 KB
testcase_08 AC 6 ms
6,944 KB
testcase_09 AC 3 ms
6,940 KB
testcase_10 AC 7 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 9 ms
6,944 KB
testcase_14 AC 13 ms
7,168 KB
testcase_15 AC 6 ms
6,944 KB
testcase_16 AC 11 ms
6,940 KB
testcase_17 AC 12 ms
6,944 KB
testcase_18 AC 5 ms
6,944 KB
testcase_19 AC 3 ms
6,940 KB
testcase_20 AC 12 ms
6,944 KB
testcase_21 AC 9 ms
6,944 KB
testcase_22 AC 11 ms
6,940 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 10 ms
6,944 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 3 ms
6,944 KB
testcase_27 AC 6 ms
6,940 KB
testcase_28 AC 3 ms
6,940 KB
testcase_29 AC 7 ms
6,944 KB
testcase_30 AC 11 ms
6,940 KB
testcase_31 AC 6 ms
6,940 KB
testcase_32 AC 6 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fn run() {
    input! {
        n: usize,
        m: usize,
        l: usize,
        a: [i64; n],
    }
    let mut ans = std::i64::MIN;
    let mut used = vec![false; n];
    for i in 0..n {
        if used[i] {
            continue;
        }
        let mut b = vec![];
        let mut index = vec![];
        let mut x = i;
        while !used[x] {
            used[x] = true;
            b.push(a[x]);
            index.push(x);
            x = (x + l) % n;
        }
        let len = b.len();
        b = b.into_iter().cycle().take(2 * len).collect();
        b.push(0);
        for i in (0..(2 * len)).rev() {
            b[i] += b[i + 1];
        }
        for (i, &x) in index.iter().enumerate() {
            if x >= l {
                continue;
            }
            let k = (n * m - x + l - 1) / l;
            ans = ans.max((k / len) as i64 * (b[i] - b[i + len]) + b[i] - b[i + k % len]);
            let x = l - (l % n + n - x) % n - 1;
            let k = (n * m - x + l - 1) / l;
            ans = ans.max((k / len) as i64 * (b[i] - b[i + len]) + b[i] - b[i + k % len]);
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}

// ---------- begin input macro ----------
// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[macro_export]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[macro_export]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[macro_export]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, bytes) => {
        read_value!($iter, String).bytes().collect::<Vec<u8>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
// ---------- end input macro ----------
0