結果

問題 No.2042 RGB Caps
ユーザー phsplsphspls
提出日時 2022-09-19 22:53:36
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,833 bytes
コンパイル時間 1,179 ms
コンパイル使用メモリ 152,544 KB
実行使用メモリ 13,780 KB
最終ジャッジ日時 2023-08-23 19:10:13
合計ジャッジ時間 4,424 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 WA -
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 17 ms
5,408 KB
testcase_08 AC 33 ms
9,272 KB
testcase_09 AC 6 ms
4,376 KB
testcase_10 AC 47 ms
12,524 KB
testcase_11 AC 4 ms
4,380 KB
testcase_12 AC 51 ms
13,768 KB
testcase_13 AC 52 ms
13,780 KB
testcase_14 AC 51 ms
13,712 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 WA -
testcase_17 AC 4 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `n`
 --> Main.rs:6:9
  |
6 |     let n = nk[0];
  |         ^ help: if this is intentional, prefix it with an underscore: `_n`
  |
  = note: `#[warn(unused_variables)]` on by default

warning: 1 warning emitted

ソースコード

diff #

fn main() {
    let mut nk = String::new();
    std::io::stdin().read_line(&mut nk).ok();
    let nk: Vec<usize> = nk.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = nk[0];
    let k = nk[1];
    let mut patterns = (0..k).map(|_| {
            let mut temp = String::new();
            std::io::stdin().read_line(&mut temp).ok();
            let temp: Vec<&str> = temp.trim().split_whitespace().collect();
            (temp[0].parse::<usize>().unwrap(), temp[1].chars().nth(0).unwrap())
        })
        .collect::<Vec<(usize, char)>>();

    patterns.sort_by_key(|&(a, _)| a);
    let mut result = vec![];
    let mut cnt = vec![0usize; 3];
    let rgb = "RGB".chars().collect::<Vec<char>>();
    for i in 0..k {
        let (a, c) = patterns[i];
        let cval = if c == 'R' { 0 } else if c == 'G' { 1 } else { 2 };
        let mut addval = vec![0usize; 3];
        let mut diff = a - cnt.iter().sum::<usize>();
        let maxval = *cnt.iter().max().unwrap();
        let minval = *cnt.iter().min().unwrap();
        if minval < maxval {
            if cnt[cval] == minval {
                diff -= 1;
                addval[cval] += 1;
            }
            for i in 0..3 {
                if cnt[i] + addval[i] == minval && diff > 0 {
                    addval[i] += 1;
                    diff -= 1;
                }
            }
        }
        addval[0] += diff/3;
        addval[1] += diff/3;
        addval[2] += diff/3;
        diff %= 3;
        if diff == 2 {
            addval[cval] += 1;
            addval[(cval + 1) % 3] += 1;
        } else if diff == 1 {
            addval[cval] += 1;
        }
        for i in 0..3 {
            result.push(rgb[i].to_string().repeat(addval[i]));
            cnt[i] += addval[i];
        }
    }
    println!("{}", result.join(""));
}
0