結果

問題 No.2858 Make a Palindrome
ユーザー QiToYQiToY
提出日時 2024-08-25 14:51:26
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,499 bytes
コンパイル時間 11,523 ms
コンパイル使用メモリ 403,056 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-08-25 14:51:42
合計ジャッジ時間 14,063 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 267 ms
6,812 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 3 ms
6,940 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 2 ms
6,940 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 2 ms
6,940 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(unused_imports)]

fn main() {
    input! {
        t: usize,
    }
    for _ in 0..t {
        input! {
            n: usize, m: usize,
            s: Chars,
        }
        let mut t = s.clone();
        t.reverse();
        if s == t {
            // include n == 1
            println!("{}", (m + n - 1) / n);
            continue;
        }
        // then n >= 2
        if s[..n - 1] == t[1..] || s[1..] == t[..n - 1] {
            // a[pal] or [pal]a
            // concat k times a[pal] => a[pal]a[pal]..a[pal]
            // longest length [pal]a[pal]..a[pal], n*k-1
            // n*k-1 >= m
            println!("{}", (m + 1 + n - 1) / n);
            continue;
        }
        println!("-1");
    }
}

/*
useuseuse
abababa
abaabaaba
abcdcbabcdcbabcdcbabcdcb
abcdcabcdcabcdcabcdcabcdc
*/

use proconio::{input, marker::*};
use std::{cmp::Reverse, collections::*};

#[macro_export]
macro_rules! chmax {
    ($a:expr, $b:expr) => {{
        let tmp = $b;
        if $a < tmp {
            $a = tmp;
            true
        } else {
            false
        }
    }};
}

#[macro_export]
macro_rules! chmin {
    ($a:expr, $b:expr) => {{
        let tmp = $b;
        if $a > tmp {
            $a = tmp;
            true
        } else {
            false
        }
    }};
}

#[macro_export]
/// mvec![]
macro_rules! mvec {
    ($val:expr; ()) => {
        $val
    };
    ($val:expr; ($size:expr $(,$rest:expr)*)) => {
        vec![mvec![$val; ($($rest),*)]; $size]
    };
}
0