結果

問題 No.1358 [Zelkova 2nd Tune *] 語るなら枚数を...
ユーザー nikkukunnikkukun
提出日時 2021-01-22 22:25:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,267 bytes
コンパイル時間 1,901 ms
コンパイル使用メモリ 165,348 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-27 20:08:52
合計ジャッジ時間 16,644 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 23 ms
4,380 KB
testcase_07 AC 19 ms
4,376 KB
testcase_08 AC 20 ms
4,376 KB
testcase_09 AC 16 ms
4,376 KB
testcase_10 AC 14 ms
4,376 KB
testcase_11 TLE -
testcase_12 TLE -
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 AC 753 ms
4,376 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 sum = 0;
	for (ll z = 0; z * c <= s; z++) {
		ll p = s - z * c;
		if (p == 0) sum++;
		if (p <= 0) continue;

		ll x, y, g;
		ExGCD(a, b, x, y, g);
		if (p % g) continue;

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

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

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

	return 0;
}
0