結果

問題 No.1358 [Zelkova 2nd Tune *] 語るなら枚数を...
ユーザー tonyu0tonyu0
提出日時 2021-01-23 00:28:36
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,388 bytes
コンパイル時間 4,291 ms
コンパイル使用メモリ 147,796 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-28 10:01:03
合計ジャッジ時間 15,039 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
4,376 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 TLE -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::*;
const MOD: i64 = 1_000_000_007;
fn ext_gcd(a: i64, b: i64, x: &mut i64, y: &mut i64) -> i64 {
    if b == 0 {
        *x = 1;
        *y = 0;
        a
    } else {
        let d = ext_gcd(b, a % b, y, x);
        *y -= (a / b) * *x;
        d
    }
}

fn calc(a: i64, b: i64, c: i64, y: i64) -> i64 {
    let mut ans = 0;
    for i in 0..=y / a {
        let d = y - i * a;

        // d = b * x + c * y
        let mut x0 = 0;
        let mut y0 = 0;
        let g = ext_gcd(b, c, &mut x0, &mut y0);
        if d % g != 0 {
            continue;
        }
        x0 *= d / g;
        y0 *= d / g;
        let bs = b / g;
        let cs = c / g;
        let u = (-y0 + bs - 1) / bs;
        x0 -= u * cs;
        if x0 >= 0 {
            ans = (ans + (x0 / cs + 1) % MOD) % MOD
        }
    }
    ans
}

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let t: usize = itr.next().unwrap().parse().unwrap();
    for _ in 0..t {
        let mut a = vec![0; 3];
        a[0] = itr.next().unwrap().parse().unwrap();
        a[1] = itr.next().unwrap().parse().unwrap();
        a[2] = itr.next().unwrap().parse().unwrap();
        let y: i64 = itr.next().unwrap().parse().unwrap();
        a.sort_by_key(|x| -x);
        println!("{}", calc(a[0], a[1], a[2], y));
    }
}
0