Submission #69327
ソースコード
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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | #ifdef DEBUG #define _GLIBCXX_DEBUG #endif #include<iostream> #include<algorithm> #include<vector> #include<string> #include<cmath> #include<queue> #include<stack> #include<map> #include<numeric> #include<climits> #include<limits>// #include <stdio.h>// #include<cmath> #include<iomanip> #include <cmath> #include <set> #include <unordered_set> #include <unordered_map> //#include <windows.h> //#include <stdlib.h> //#include <atcoder/all> using namespace std; //using namespace atcoder; #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef long long ll; template < class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true ); } template < class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true ); } int dy[] = {1, 0, -1, 0}; int dx[] = {0, 1, 0, -1}; double pie = 3.14159265358979323846264338; \ ll updiv(ll a, ll b){ return ((a + b - 1) / b); } //using mint = modint998244353; //using mint = modint1000000007; bool Pn ( int a){ if (a == 1){ return ( false ); } if (a == 2){ return ( true ); } if (a % 2 == 0){ return ( false ); } int n = sqrt (a); for ( int i = 3; i <= n; i+=2){ if (a % i == 0){ return ( false ); } } return ( true ); } bool PrimeNumber ( int a){ if (a == 1){ return ( false ); } if (a == 2){ return ( true ); } if (a % 2 == 0){ return ( false ); } int m = sqrt (a); for ( int i = 0; i <= m; i++){ if (a % i == 0){ return ( false ); } } return ( true ); } int main(){ cin.tie(0); ios::sync_with_stdio( false ); int n; cin >> n; vector< int > a(n); vector<vector<ll>> mp(n+1,vector<ll> (40010)); mp[0][20005] = 1; for ( int i = 0; i < n; i++){ cin >> a[i]; } for ( int i = 0; i < n; i++){ for ( int j = 0; j <= 40005; j++){ if (j+a[i] > 40005){ mp[i+1][j] = mp[i][j-a[i]] % 998244353; } else if (j-a[i] < 0){ mp[i+1][j] = mp[i][j+a[i]] % 998244353; } else { mp[i+1][j] = (mp[i][j+a[i]] + mp[i][j-a[i]]) % 998244353; } } } cout << (mp[n][20005]) % 998244353 << '\n' ; return 0; } |
ステータス
項目 | データ |
---|---|
問題 | 1529 - Red Black Balls |
ユーザー名 | kumakuma |
投稿日時 | 2022-03-29 09:07:26 |
言語 | C++17 |
状態 | Accepted |
得点 | 3 |
ソースコード長 | 2266 Byte |
最大実行時間 | 75 ms |
最大メモリ使用量 | 64668 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 3 / 3 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
in01.txt | AC | 29 ms | 2780 KB |
1
|
in02.txt | AC | 27 ms | 4880 KB |
1
|
in03.txt | AC | 21 ms | 2076 KB |
1
|
in04.txt | AC | 24 ms | 4932 KB |
1
|
in05.txt | AC | 18 ms | 4944 KB |
1
|
in06.txt | AC | 18 ms | 3416 KB |
1
|
in07.txt | AC | 18 ms | 2452 KB |
1
|
in08.txt | AC | 22 ms | 5884 KB |
1
|
in09.txt | AC | 24 ms | 3668 KB |
1
|
in10.txt | AC | 26 ms | 7512 KB |
1
|
in11.txt | AC | 52 ms | 37512 KB |
1
|
in12.txt | AC | 41 ms | 20208 KB |
1
|
in13.txt | AC | 68 ms | 62516 KB |
1
|
in14.txt | AC | 39 ms | 22288 KB |
1
|
in15.txt | AC | 71 ms | 56372 KB |
1
|
in16.txt | AC | 61 ms | 58636 KB |
1
|
in17.txt | AC | 53 ms | 37816 KB |
1
|
in18.txt | AC | 27 ms | 7644 KB |
1
|
in19.txt | AC | 64 ms | 53328 KB |
1
|
in20.txt | AC | 57 ms | 54528 KB |
1
|
in21.txt | AC | 42 ms | 23868 KB |
1
|
in22.txt | AC | 53 ms | 42548 KB |
1
|
in23.txt | AC | 24 ms | 10324 KB |
1
|
in24.txt | AC | 63 ms | 53600 KB |
1
|
in25.txt | AC | 25 ms | 10960 KB |
1
|
in26.txt | AC | 70 ms | 64484 KB |
1
|
in27.txt | AC | 64 ms | 64476 KB |
1
|
in28.txt | AC | 66 ms | 64464 KB |
1
|
in29.txt | AC | 75 ms | 64456 KB |
1
|
in30.txt | AC | 67 ms | 64576 KB |
1
|
in31.txt | AC | 63 ms | 64556 KB |
1
|
in32.txt | AC | 70 ms | 64668 KB |
1
|
in33.txt | AC | 72 ms | 64140 KB |
1
|
in34.txt | AC | 63 ms | 64188 KB |
1
|
in35.txt | AC | 64 ms | 64236 KB |
1
|
in36.txt | AC | 61 ms | 64284 KB |
1
|
in37.txt | AC | 16 ms | 1868 KB |
1
|
in38.txt | AC | 21 ms | 1836 KB |
1
|
in39.txt | AC | 20 ms | 2192 KB |
1
|
in40.txt | AC | 17 ms | 2228 KB |
1
|
sample01.txt | AC | 19 ms | 3292 KB |
1
|
sample02.txt | AC | 23 ms | 2000 KB |
1
|