Submission #62487
ソースコード
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | #pragma GCC optimize("O3") #include <bits/stdc++.h> #define ll long long #define rep(i,n) for(ll i=0;i<(n);i++) #define pll pair<ll,ll> #define pii pair<int,int> #define pq priority_queue #define pb push_back #define eb emplace_back #define fi first #define se second #define endl '\n' #define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0); #define lb(c,x) distance(c.begin(),lower_bound(all(c),x)) #define ub(c,x) distance(c.begin(),upper_bound(all(c),x)) using namespace std; template < class T> inline bool chmax(T& a,T b){ if (a<b){a=b; return 1;} return 0;} template < class T> inline bool chmin(T& a,T b){ if (a>b){a=b; return 1;} return 0;} const ll INF=1e9+7; const ll mod = 998244353; struct mint { ll x; // typedef long long ll; mint(ll x=0):x((x%mod+mod)%mod){} mint operator-() const { return mint(-x);} mint& operator+=( const mint a) { if ((x += a.x) >= mod) x -= mod; return * this ; } mint& operator-=( const mint a) { if ((x += mod-a.x) >= mod) x -= mod; return * this ; } mint& operator*=( const mint a) { (x *= a.x) %= mod; return * this ;} mint operator+( const mint a) const { return mint(* this ) += a;} mint operator-( const mint a) const { return mint(* this ) -= a;} mint operator*( const mint a) const { return mint(* this ) *= a;} mint pow (ll t) const { if (!t) return 1; mint a = pow (t>>1); a *= a; if (t&1) a *= * this ; return a; } // for prime mod mint inv() const { return pow (mod-2);} mint& operator/=( const mint a) { return * this *= a.inv();} mint operator/( const mint a) const { return mint(* this ) /= a;} }; istream& operator>>(istream& is, mint& a) { return is >> a.x;} ostream& operator<<(ostream& os, const mint& a) { return os << a.x;} // combination mod prime struct combination { vector<mint> fact, ifact; combination(ll n):fact(n+1),ifact(n+1) { assert (n < mod); fact[0] = 1; for (ll i = 1; i <= n; ++i) fact[i] = fact[i-1]*i; ifact[n] = fact[n].inv(); for (ll i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i; } mint operator()(ll n, ll k) { if (k < 0 || k > n) return 0; return fact[n]*ifact[k]*ifact[n-k]; } mint p(ll n, ll k) { return fact[n]*ifact[n-k]; } } c(1000005); int main(){ ios; int n; cin >> n; vector< int > a(n),p(n); mint v=2; rep(i,n){ cin >> a[i]; p[i]=v. pow (a[i]).x-1; } vector<mint> dp1(n+1),dp2(n+1); dp1[0]=1,dp2[0]=1; rep(i,n){ //i番目まで見たとき、j種類選ぶ方法 for ( int j=1;j<=n;j++){ dp1[j]=dp2[j]+dp2[j-1]*p[i]; } dp2=dp1; } rep(i,n){ dp2[i+1]+=dp2[i]; } int q; cin >> q; rep(i,q){ int l,r; cin >> l >> r; l--; cout << dp2[r]-dp2[l] << endl; } return 0; } |
ステータス
項目 | データ |
---|---|
問題 | 1351 - Colorful Balls |
ユーザー名 | unos |
投稿日時 | 2020-08-18 21:25:14 |
言語 | C++17 |
状態 | Accepted |
得点 | 100 |
ソースコード長 | 2979 Byte |
最大実行時間 | 285 ms |
最大メモリ使用量 | 80112 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 100 / 100 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
input01 | AC | 29 ms | 16216 KB |
1
|
input02 | AC | 33 ms | 16288 KB |
1
|
input03 | AC | 29 ms | 16096 KB |
1
|
input04 | AC | 30 ms | 16164 KB |
1
|
input05 | AC | 30 ms | 16100 KB |
1
|
input06 | AC | 31 ms | 16168 KB |
1
|
input07 | AC | 31 ms | 16232 KB |
1
|
input08 | AC | 27 ms | 16164 KB |
1
|
input09 | AC | 35 ms | 16228 KB |
1
|
input10 | AC | 26 ms | 16268 KB |
1
|
input11 | AC | 61 ms | 18368 KB |
1
|
input12 | AC | 137 ms | 25332 KB |
1
|
input13 | AC | 169 ms | 31276 KB |
1
|
input14 | AC | 190 ms | 35100 KB |
1
|
input15 | AC | 49 ms | 35304 KB |
1
|
input16 | AC | 152 ms | 37104 KB |
1
|
input17 | AC | 260 ms | 45240 KB |
1
|
input18 | AC | 285 ms | 54904 KB |
1
|
input19 | AC | 244 ms | 64572 KB |
1
|
input20 | AC | 174 ms | 73368 KB |
1
|
input21 | AC | 153 ms | 74704 KB |
1
|
input22 | AC | 125 ms | 74772 KB |
1
|
input23 | AC | 128 ms | 80088 KB |
1
|
input_sample01 | AC | 31 ms | 80112 KB |
1
|
input_sample02 | AC | 26 ms | 80052 KB |
1
|