結果
問題 | No.1358 [Zelkova 2nd Tune *] 語るなら枚数を... |
ユーザー | tokusakurai |
提出日時 | 2021-01-22 21:48:20 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 357 ms / 2,000 ms |
コード長 | 3,789 bytes |
コンパイル時間 | 2,352 ms |
コンパイル使用メモリ | 210,920 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-08 14:21:09 |
合計ジャッジ時間 | 5,350 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 6 ms
5,376 KB |
testcase_07 | AC | 5 ms
5,376 KB |
testcase_08 | AC | 5 ms
5,376 KB |
testcase_09 | AC | 4 ms
5,376 KB |
testcase_10 | AC | 4 ms
5,376 KB |
testcase_11 | AC | 324 ms
5,376 KB |
testcase_12 | AC | 281 ms
5,376 KB |
testcase_13 | AC | 357 ms
5,376 KB |
testcase_14 | AC | 262 ms
5,376 KB |
testcase_15 | AC | 279 ms
5,376 KB |
testcase_16 | AC | 330 ms
5,376 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < n; i++) #define rep2(i, x, n) for(int i = x; i <= n; i++) #define rep3(i, x, n) for(int i = x; i >= n; i--) #define each(e, v) for(auto &e: v) #define pb push_back #define eb emplace_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define sz(x) (int)x.size() using ll = long long; using pii = pair<int, int>; using pil = pair<int, ll>; using pli = pair<ll, int>; using pll = pair<ll, ll>; const int MOD = 1000000007; //const int MOD = 998244353; const int inf = (1<<30)-1; const ll INF = (1LL<<60)-1; template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;}; template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;}; struct io_setup{ io_setup(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout << fixed << setprecision(15); } } io_setup; template<typename T> T gcd(const T &a, const T &b){ if(b == 0) return a; else return gcd(b, a%b); } template<typename T> T lcm(const T &a, const T &b) {return a*(b/gcd(a,b));} template<typename T> T extgcd(const T &a, const T &b, T &x, T &y){ if(b == 0) {x = 1, y = 0; return a;} T g = extgcd(b, a%b, y, x); y -= (a/b)*x; return g; } int mod(const ll &a, const int &m){ int ret = a%m; return ret+(ret < 0? m : 0); } int modinv(const int &a, const int &m){ //aとmは互いに素 int x, y; extgcd(a, m, x, y); return mod(x, m); } template<typename T> T floor_sum(const T &n, const T &m, T a, T b){ //Σ(floor((a*i+b)/m)) (0<=i<n) T ret = (a/m)*(n*(n-1)/2)+(b/m)*n; a %= m, b %= m; T y = (a*n+b)/m; if(y == 0) return ret; ret += floor_sum(y, a, m, a*n-(m*y-b)); return ret; } template<typename T> pair<T, T> Chinese_reminder_theorem(const T &a1, const T &m1, const T &a2, const T &m2){ T x, y, g = extgcd(m1, m2, x, y); if((a2-a1)%g != 0) return make_pair(0, -1); T m = m1*(m2/g); T tmp = mod(x*((a2-a1)/g), m2/g); T a = (m1*tmp+a1) % m; return make_pair(a, m); } bool prepare_Garner(vector<int> &a, vector<int> &m){ int n = sz(a); rep(i, n){ rep(j, i){ int g = gcd(m[i], m[j]); if((a[i]-a[j])%g != 0) return false; m[i] /= g, m[j] /= g; int gi = gcd(m[i], g), gj = g/gi; do{ g = gcd(gi, gj); gi *= g, gj /= g; } while(g > 1); m[i] *= gi, m[j] *= gj; } } return true; } int Garner(vector<int> a, vector<int> m, const int &M){ //mの各要素はそれぞれ互いに素 m.pb(M); vector<ll> coeffs(sz(m), 1); vector<ll> constants(sz(m), 0); rep(k, sz(a)){ ll x = a[k]-constants[k], y = modinv(coeffs[k], m[k]); ll t = mod(x*y, m[k]); rep2(i, k+1, sz(m)-1){ constants[i] += t*coeffs[i], constants[i] %= m[i]; coeffs[i] *= m[k], coeffs[i] %= m[i]; } } return constants.back(); } int main(){ int T; cin >> T; while(T--){ vector<ll> A(3); ll B; rep(i, 3) cin >> A[i]; cin >> B; sort(rall(A)); ll G = gcd(A[1], A[2]); ll a = A[1]/G, b = A[2]/G; ll ans = 0; ll X, Y; extgcd(A[1], A[2], X, Y); for(ll i = 0; A[0]*i <= B; i++){ ll C = B-A[0]*i; if(C%G != 0) continue; ll x, y; x = X*(C/G), y = Y*(C/G); ll L, R; if(y >= 0) R = y/a; else R = -((-y+a-1)/a); if(x <= 0) L = (-x+b-1)/b; else L = -(x/b); ans += (R-L+1), ans %= MOD; } cout << ans << '\n'; } }