結果
| 問題 |
No.2561 みんな大好きmod 998
|
| コンテスト | |
| ユーザー |
ragna
|
| 提出日時 | 2023-10-30 02:36:56 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2,666 ms / 4,000 ms |
| コード長 | 1,470 bytes |
| コンパイル時間 | 1,656 ms |
| コンパイル使用メモリ | 183,604 KB |
| 実行使用メモリ | 509,312 KB |
| 最終ジャッジ日時 | 2024-09-25 22:29:44 |
| 合計ジャッジ時間 | 10,747 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 44 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:26:20: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
26 | for(auto&& [x,y]:dp[i]){
| ^
main.cpp:37:16: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
37 | for(auto&& [x,y]:dp[n]){
| ^
ソースコード
#include<bits/stdc++.h>
//#include<atcoder/modint>
//using mint=atcoder::modint998244353;
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rrep(i,a,b) for(ll i=(ll)(a-1);i>=(ll)(b);i--)
#define MOD 998244353
//#define MOD 1000000007
#define INF 1e18
#define Pair pair<ll,ll>
//#define PI numbers::pi
//#define E numbers::e
template <typename T> bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
ll dx[8]={-2,-1,1,2,-2,-1,1,2};
ll dy[8]={-1,-2,-2,-1,1,2,2,1};
int main(){
ll n,k; cin >> n >> k;
vector<ll> a(n);
rep(i,0,n) cin >> a[i];
vector<map<pair<Pair,ll>,ll>> dp(n+1);
dp[0][{{0,0},0}]=1;
rep(i,0,n){
for(auto&& [x,y]:dp[i]){
ll p=x.first.first,q=x.first.second,r=x.second;
if(r==k) dp[i+1][x]=(dp[i+1][x]+y)%998;
else if(n-i+r==k&&(p+a[i]%998)%998>=(q+a[i]%MOD)%MOD) dp[i+1][{{(p+a[i]%998)%998,(q+a[i]%MOD)%MOD},r+1}]=(dp[i+1][{{(p+a[i]%998)%998,(q+a[i]%MOD)%MOD},r+1}]+y)%998;
else{
dp[i+1][x]=(dp[i+1][x]+y)%998;
if(r<k-1||(p+a[i]%998)%998>=(q+a[i]%MOD)%MOD) dp[i+1][{{(p+a[i]%998)%998,(q+a[i]%MOD)%MOD},r+1}]=(dp[i+1][{{(p+a[i]%998)%998,(q+a[i]%MOD)%MOD},r+1}]+y)%998;
}
}
}
ll ans=0;
for(auto&& [x,y]:dp[n]){
if(x.second==k) ans=(ans+y)%998;
}
cout << ans << endl;
}
ragna