提出 #49589945
ソースコード 拡げる
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,a,n) for (ll i=a;i<(ll)(n);i++) #define per(i,a,n) for (ll i=n;i-->(ll)(a);) ll read(){ll r;scanf("%lld",&r);return r;} // ax+by=c, gcd(a,b) = 1, return {x,y} // ((a/b)*b+a%b) x + by = c // b (y+(a/b)x) + (a%b) x = c tuple<ll,ll> exgcd(ll a,ll b,ll c){ if(b == 0) return {c/a, 1}; auto [_x,_y] = exgcd(b,a%b,c); return {_y,_x - (a/b) * _y}; } ll mod(ll a,ll b){return (a%b+b)%b;} // a = kb + [0,b) return k ll floordiv(ll a,ll b){ return (a-mod(a,b))/b; } // a = kb + (-b,0] return k ll ceildiv(ll a,ll b){ return (a-mod(a,b))/b + int(mod(a,b) != 0); } // count( (x,y) \in[1,n]) // ax+by=c ll solve(ll a,ll b,ll c,ll n){ if(c <= 0) return 0; ll m = gcd(a,b); if(c % m != 0) return 0; a/=m; b/=m; c/=m; auto [x,y] = exgcd(a,b,c); // gcd(a,b) = 1 // (x+kb,y-ka) // 1 <= x+kb <= n // 1 <= y-ka <= n // (1-x)/b <= k <= (n-x)/b // (y-n)/a <= k <= (y-1)/a ll maxk = min(floordiv(n-x,b),floordiv(y-1,a)); ll mink = max(ceildiv(1-x,b),ceildiv(y-n,a)); auto bound=[&](ll v){return 1<=v and v<=n;}; while(mink <= maxk and (!bound(x+mink*b) or !bound(y-mink*a))) mink++; while(mink <= maxk and (!bound(x+maxk*b) or !bound(y-maxk*a))) maxk--; return maxk >= mink ? maxk-mink+1:0; } int main(){ // ai + bj + ck = x // count( (i,j,k) \in [1,n]) ll n = read(); // 1e6 ll a = read(); // [1,1e9] ll b = read(); // [1,1e9] ll c = read(); // [1,1e9] ll x = read(); // [1,3e15] ll m = gcd(gcd(a,b),gcd(c,x)); a/=m; b/=m; c/=m; x/=m; ll ans = 0; rep(i,1,n+1) ans += solve(b,c,x-a*i,n); printf("%lld\n",ans); return 0; } // 非常质朴的一道题 // 很有gcd/exgcd的想法 // a,b,c,x // 就暴力for i,然后exgcd没了??
提出情報
提出日時 | |
---|---|
問題 | G - Ai + Bj + Ck = X (1 <= i, j, k <= N) |
ユーザ | cromarmot |
言語 | C++ 20 (gcc 12.2) |
得点 | 0 |
コード長 | 1766 Byte |
結果 | WA |
実行時間 | 220 ms |
メモリ | 3884 KiB |
コンパイルエラー
Main.cpp: In function ‘ll read()’: Main.cpp:8:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 8 | ll read(){ll r;scanf("%lld",&r);return r;} | ~~~~~^~~~~~~~~~~
ジャッジ結果
セット名 | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
得点 / 配点 | 0 / 0 | 0 / 550 | ||||||
結果 |
|
|
セット名 | テストケース |
---|---|
Sample | sample_01.txt, sample_02.txt, sample_03.txt |
All | sample_01.txt, sample_02.txt, sample_03.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt, test_28.txt, test_29.txt, test_30.txt, test_31.txt, test_32.txt, test_33.txt, test_34.txt, test_35.txt, test_36.txt, test_37.txt, test_38.txt, test_39.txt, test_40.txt, test_41.txt, test_42.txt, test_43.txt, test_44.txt, test_45.txt, test_46.txt, test_47.txt, test_48.txt, test_49.txt, test_50.txt, test_51.txt, test_52.txt, test_53.txt, test_54.txt, test_55.txt, test_56.txt, test_57.txt, test_58.txt, test_59.txt, test_60.txt, test_61.txt, test_62.txt, test_63.txt, test_64.txt, test_65.txt, test_66.txt, test_67.txt, test_68.txt, test_69.txt, test_70.txt, test_71.txt, test_72.txt, test_73.txt, test_74.txt, test_75.txt, test_76.txt, test_77.txt, test_78.txt, test_79.txt, test_80.txt, test_81.txt, test_82.txt, test_83.txt, test_84.txt, test_85.txt, test_86.txt, test_87.txt, test_88.txt, test_89.txt, test_90.txt, test_91.txt, test_92.txt, test_93.txt, test_94.txt, test_95.txt, test_96.txt, test_97.txt, test_98.txt |
ケース名 | 結果 | 実行時間 | メモリ |
---|---|---|---|
sample_01.txt | AC | 1 ms | 3764 KiB |
sample_02.txt | AC | 1 ms | 3756 KiB |
sample_03.txt | AC | 6 ms | 3668 KiB |
test_01.txt | AC | 1 ms | 3624 KiB |
test_02.txt | AC | 1 ms | 3680 KiB |
test_03.txt | AC | 1 ms | 3672 KiB |
test_04.txt | AC | 1 ms | 3752 KiB |
test_05.txt | AC | 1 ms | 3688 KiB |
test_06.txt | AC | 1 ms | 3812 KiB |
test_07.txt | AC | 1 ms | 3816 KiB |
test_08.txt | AC | 1 ms | 3624 KiB |
test_09.txt | AC | 1 ms | 3812 KiB |
test_10.txt | AC | 1 ms | 3628 KiB |
test_11.txt | AC | 1 ms | 3876 KiB |
test_12.txt | AC | 1 ms | 3752 KiB |
test_13.txt | AC | 1 ms | 3752 KiB |
test_14.txt | AC | 1 ms | 3664 KiB |
test_15.txt | AC | 1 ms | 3764 KiB |
test_16.txt | AC | 1 ms | 3748 KiB |
test_17.txt | AC | 1 ms | 3624 KiB |
test_18.txt | AC | 1 ms | 3752 KiB |
test_19.txt | AC | 1 ms | 3876 KiB |
test_20.txt | AC | 1 ms | 3624 KiB |
test_21.txt | AC | 1 ms | 3624 KiB |
test_22.txt | AC | 1 ms | 3624 KiB |
test_23.txt | AC | 1 ms | 3816 KiB |
test_24.txt | AC | 1 ms | 3752 KiB |
test_25.txt | AC | 1 ms | 3684 KiB |
test_26.txt | AC | 1 ms | 3684 KiB |
test_27.txt | AC | 1 ms | 3820 KiB |
test_28.txt | AC | 1 ms | 3584 KiB |
test_29.txt | AC | 1 ms | 3748 KiB |
test_30.txt | AC | 1 ms | 3680 KiB |
test_31.txt | AC | 1 ms | 3624 KiB |
test_32.txt | AC | 1 ms | 3584 KiB |
test_33.txt | AC | 1 ms | 3884 KiB |
test_34.txt | AC | 1 ms | 3768 KiB |
test_35.txt | AC | 1 ms | 3820 KiB |
test_36.txt | AC | 1 ms | 3748 KiB |
test_37.txt | AC | 1 ms | 3668 KiB |
test_38.txt | AC | 1 ms | 3876 KiB |
test_39.txt | AC | 1 ms | 3680 KiB |
test_40.txt | AC | 1 ms | 3620 KiB |
test_41.txt | AC | 1 ms | 3820 KiB |
test_42.txt | AC | 1 ms | 3688 KiB |
test_43.txt | AC | 1 ms | 3644 KiB |
test_44.txt | AC | 1 ms | 3580 KiB |
test_45.txt | AC | 1 ms | 3812 KiB |
test_46.txt | AC | 1 ms | 3752 KiB |
test_47.txt | AC | 1 ms | 3688 KiB |
test_48.txt | AC | 1 ms | 3752 KiB |
test_49.txt | AC | 1 ms | 3820 KiB |
test_50.txt | AC | 42 ms | 3624 KiB |
test_51.txt | AC | 26 ms | 3656 KiB |
test_52.txt | AC | 42 ms | 3608 KiB |
test_53.txt | AC | 8 ms | 3692 KiB |
test_54.txt | AC | 78 ms | 3584 KiB |
test_55.txt | AC | 8 ms | 3876 KiB |
test_56.txt | AC | 10 ms | 3884 KiB |
test_57.txt | AC | 39 ms | 3788 KiB |
test_58.txt | AC | 42 ms | 3756 KiB |
test_59.txt | AC | 5 ms | 3876 KiB |
test_60.txt | AC | 5 ms | 3688 KiB |
test_61.txt | AC | 5 ms | 3880 KiB |
test_62.txt | AC | 22 ms | 3872 KiB |
test_63.txt | AC | 3 ms | 3680 KiB |
test_64.txt | AC | 3 ms | 3816 KiB |
test_65.txt | AC | 42 ms | 3816 KiB |
test_66.txt | AC | 78 ms | 3764 KiB |
test_67.txt | AC | 71 ms | 3820 KiB |
test_68.txt | AC | 98 ms | 3816 KiB |
test_69.txt | WA | 101 ms | 3772 KiB |
test_70.txt | AC | 2 ms | 3688 KiB |
test_71.txt | AC | 93 ms | 3812 KiB |
test_72.txt | AC | 19 ms | 3652 KiB |
test_73.txt | AC | 73 ms | 3816 KiB |
test_74.txt | WA | 34 ms | 3876 KiB |
test_75.txt | AC | 17 ms | 3760 KiB |
test_76.txt | AC | 55 ms | 3884 KiB |
test_77.txt | AC | 11 ms | 3768 KiB |
test_78.txt | AC | 1 ms | 3756 KiB |
test_79.txt | WA | 21 ms | 3816 KiB |
test_80.txt | AC | 59 ms | 3684 KiB |
test_81.txt | AC | 93 ms | 3876 KiB |
test_82.txt | AC | 4 ms | 3768 KiB |
test_83.txt | WA | 107 ms | 3628 KiB |
test_84.txt | WA | 116 ms | 3648 KiB |
test_85.txt | AC | 65 ms | 3764 KiB |
test_86.txt | WA | 176 ms | 3756 KiB |
test_87.txt | WA | 147 ms | 3880 KiB |
test_88.txt | WA | 159 ms | 3580 KiB |
test_89.txt | WA | 54 ms | 3584 KiB |
test_90.txt | WA | 220 ms | 3816 KiB |
test_91.txt | WA | 156 ms | 3684 KiB |
test_92.txt | WA | 133 ms | 3580 KiB |
test_93.txt | WA | 179 ms | 3624 KiB |
test_94.txt | WA | 156 ms | 3672 KiB |
test_95.txt | WA | 185 ms | 3872 KiB |
test_96.txt | WA | 103 ms | 3628 KiB |
test_97.txt | WA | 81 ms | 3764 KiB |
test_98.txt | AC | 87 ms | 3672 KiB |