結果

問題 No.188 HAPPY DAY
ユーザー YoshihitoYoshihito
提出日時 2020-01-26 20:44:11
言語 Rust
(1.77.0)
結果
AC  
実行時間 1 ms / 1,000 ms
コード長 1,271 bytes
コンパイル時間 1,427 ms
コンパイル使用メモリ 135,564 KB
実行使用メモリ 4,368 KB
最終ジャッジ日時 2023-10-12 12:36:26
合計ジャッジ時間 1,876 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::cmp;

static MONTH_DAYS: &'static [i32] = &[
    0,  // dummy
    31, // Jan
    28, // Feb
    31, // Mar
    30, // Apr
    31, // May
    30, // Jun
    31, // Jul
    31, // Aug
    30, // Sep
    31, // Oct
    30, // Nov
    31, // Dec
];

fn solve() {
    // 1..9
    // - 1 : 01 - 10, (01, 10)
    // - 2 : 02 - 20, (12, 11, 20)
    // - 3 : 03 - 30, (03, 12, 21, 30)
    // - 4 : 04 - max (04, 13, 22),     NG: 31
    // - 5 : 05 - max (05, 14, 23),     NG: 32, 41
    // ...
    // - 9 : 09 - max (09, 18, 27),     NG: 36, 45, ...

    // 10..12
    // - 10 : 10 - max (19, 28),        NG : 37, 46, ...
    // - 11 : 11 - max (29),            NG : 38, 47, ...
    // - 12 : 12 - max (),              NG : 39, 48, ...

    let mut count = 0;
    for month in 1..=12 {
        let start = if month < 10 {
            month
        } else {
            (month - 9) * 10 + 9
        };
        let stop = cmp::min(month * 10, MONTH_DAYS[month as usize]);
        if start > stop {
            break;
        }

        for offset in 0..4 {
            let happy_day = start + offset * 9;
            if happy_day > stop {
                break;
            }

            count += 1;
        }
    }
    println!("{}", count);
}

fn main() {
    solve();
}
0