結果

問題 No.1358 [Zelkova 2nd Tune *] 語るなら枚数を...
ユーザー nikkukunnikkukun
提出日時 2021-01-22 23:35:32
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 573 ms / 2,000 ms
コード長 1,284 bytes
コンパイル時間 1,503 ms
コンパイル使用メモリ 164,904 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-27 23:08:39
合計ジャッジ時間 5,024 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 7 ms
4,376 KB
testcase_07 AC 6 ms
4,380 KB
testcase_08 AC 6 ms
4,376 KB
testcase_09 AC 6 ms
4,380 KB
testcase_10 AC 5 ms
4,376 KB
testcase_11 AC 500 ms
4,376 KB
testcase_12 AC 449 ms
4,380 KB
testcase_13 AC 573 ms
4,376 KB
testcase_14 AC 394 ms
4,380 KB
testcase_15 AC 437 ms
4,376 KB
testcase_16 AC 550 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define lch (o << 1)
#define rch (o << 1 | 1)

typedef double db;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> pint;
typedef tuple<int, int, int> tint;

const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const ll INF_LL = 0x3f3f3f3f3f3f3f3f;

void ExGCD(ll a, ll b, ll &x, ll &y, ll &g) {
	if (!b)
		x = 1, y = 0, g = a;
	else
		ExGCD(b, a % b, y, x, g), y -= x * (a / b);
}

ll divCeil(ll upp, ll low) {
	if (upp < 0)
		return upp / low;
	else
		return (upp + low - 1) / low;
}

ll divFloor(ll upp, ll low) {
	if (upp > 0)
		return upp / low;
	else
		return (upp - low + 1) / low;
}

void solve() {
	ll a, b, c, s;
	cin >> a >> b >> c >> s;

	if (s / a < s / c) swap(a, c);
	if (s / b < s / c) swap(b, c);

	ll x, y, g;
	ExGCD(a, b, x, y, g);

	ll sum = 0;
	ll zUpp = s / c;
	for (ll z = 0; z <= zUpp; z++) {
		ll p = s - z * c;
		if (p == 0) sum++;
		if (p <= 0) continue;
		if (p % g) continue;

		ll L = divCeil(-x * (p / g), b / g);
		ll R = divFloor(y * (p / g), a / g);
		if (L <= R) sum += R - L + 1;
	}
	cout << sum % MOD << endl;
}

int main() {
	ios::sync_with_stdio(0);

	int t;
	cin >> t;
	while (t--) solve();

	return 0;
}
0