Submission #2609272
Source Code Expand
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf_int=1e8; const ll inf_ll=1e16; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef long double dbl; #define pb push_back const double pi=3.1415926535898; #define dout if(debug) cout #define fi first #define se second #define sp setprecision #define sz(a) (int(a.size())) #define all(a) a.begin(),a.end() bool debug = 0; const int MAXN = 3e5+10; const int LOG = 20; const int mod =998244353; ll bin_pow(ll a,int n){ ll res = 1; while(n){ if(n&1){ res = (res * a)%mod; } a = (a*a)%mod; n>>=1; } return res; } ll rev(ll x){ return bin_pow(x,mod-2); } ll fac[MAXN]; ll rev_fac[MAXN]; ll A,B; void precalc(){ fac[0] = 1; rev_fac[0] = 1; for(int i=1;i<MAXN;++i){ fac[i] =(fac[i-1] * i)%mod; rev_fac[i] = rev(fac[i]); } } ll C(int n,int k){ return ( (fac[n] * rev_fac[k])%mod * rev_fac[n-k] )%mod; } void solve(){ int n; cin >> n; cin >> A >> B; ll k; cin >> k; if(k==0){ cout <<1; return; } precalc(); ll ans = 0; for(int m=0;m<=n;++m){ //m total green and red dout << m<< " : "<<endl; if(m * A > k) continue; ll x = (k - m * A); if(x%B!=0) continue; dout <<"x "<< x<<endl; x = x / B; if(x<0 || x>n){ continue; } ll cur = (C(n,m) * C(n,x))%mod; ans+=cur; if(ans>=mod) ans-=mod; } cout << ans<<"\n"; } signed main() { #ifdef taow freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); #else #endif // taow ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(20); int t = 1; while(t--) solve(); }
Submission Info
Submission Time | |
---|---|
Task | B - RGB Coloring |
User | taow |
Language | C++14 (GCC 5.4.1) |
Score | 700 |
Code Size | 2115 Byte |
Status | AC |
Exec Time | 58 ms |
Memory | 4992 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 700 / 700 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample01.txt, sample02.txt, sample03.txt |
All | sample01.txt, sample02.txt, sample03.txt, in01.txt, in02.txt, in03.txt, in04.txt, in05.txt, in06.txt, in07.txt, in08.txt, in09.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in20.txt, in21.txt, sample01.txt, sample02.txt, sample03.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
in01.txt | AC | 53 ms | 4992 KB |
in02.txt | AC | 56 ms | 4992 KB |
in03.txt | AC | 51 ms | 4992 KB |
in04.txt | AC | 53 ms | 4992 KB |
in05.txt | AC | 53 ms | 4992 KB |
in06.txt | AC | 51 ms | 4992 KB |
in07.txt | AC | 53 ms | 4992 KB |
in08.txt | AC | 51 ms | 4992 KB |
in09.txt | AC | 53 ms | 4992 KB |
in10.txt | AC | 52 ms | 4992 KB |
in11.txt | AC | 51 ms | 4992 KB |
in12.txt | AC | 51 ms | 4992 KB |
in13.txt | AC | 51 ms | 4992 KB |
in14.txt | AC | 50 ms | 4992 KB |
in15.txt | AC | 50 ms | 4992 KB |
in16.txt | AC | 50 ms | 4992 KB |
in17.txt | AC | 53 ms | 4992 KB |
in18.txt | AC | 58 ms | 4992 KB |
in19.txt | AC | 58 ms | 4992 KB |
in20.txt | AC | 58 ms | 4992 KB |
in21.txt | AC | 1 ms | 256 KB |
sample01.txt | AC | 49 ms | 4992 KB |
sample02.txt | AC | 1 ms | 256 KB |
sample03.txt | AC | 50 ms | 4992 KB |