結果

問題 No.1358 [Zelkova 2nd Tune *] 語るなら枚数を...
ユーザー roarisroaris
提出日時 2021-01-23 19:18:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,385 bytes
コンパイル時間 2,069 ms
コンパイル使用メモリ 200,116 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-30 03:47:29
合計ジャッジ時間 15,630 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007;

int extGCD(int a, int b, int &x, int &y) {
    if (b==0) {
        x = 1;
        y = 0;
        return a;
    }
    int d = extGCD(b, a%b, y, x);
    y -= a/b * x;
    return d;
}

signed main() {
    int T; cin >> T;
    int x, y;
    
    while (T--) {
        int N, K, H, Y; cin >> N >> K >> H >> Y;
        int M = max({N, K, H});
        int c = Y/M;
        int ans = 0;
        
        for (int i=0; i<=c; i++) {
            int nokori = Y-i*M;
            
            if (M==N) {
                int G = extGCD(K, H, x, y);
                if (nokori%G==0) {
                    x *= nokori/G;
                    y *= nokori/G;
                    ans += y/K-(-x+H-1)/H+1;
                }
            }
            else if (M==K) {
                int G = extGCD(H, N, x, y);
                if (nokori%G==0) {
                    x *= nokori/G;
                    y *= nokori/G;
                    ans += y/H-(-x+N-1)/N+1;
                }
            }
            else {
                int G = extGCD(N, K, x, y);
                if (nokori%G==0) {
                    x *= nokori/G;
                    y *= nokori/G;
                    ans += y/N-(-x+K-1)/K+1;
                }
            }
            ans %= MOD;
        }
        cout << ans << endl;
    }
}
0