結果

問題 No.2561 みんな大好きmod 998
ユーザー ragnaragna
提出日時 2023-10-30 02:36:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,722 ms / 4,000 ms
コード長 1,470 bytes
コンパイル時間 1,851 ms
コンパイル使用メモリ 184,040 KB
実行使用メモリ 509,540 KB
最終ジャッジ日時 2023-11-05 13:20:06
合計ジャッジ時間 11,289 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2,655 ms
509,540 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 5 ms
4,660 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 376 ms
79,588 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2,722 ms
509,468 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 1,996 ms
377,956 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 1 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 494 ms
104,116 KB
testcase_27 AC 5 ms
4,348 KB
testcase_28 AC 3 ms
4,348 KB
testcase_29 AC 4 ms
4,348 KB
testcase_30 AC 4 ms
4,348 KB
testcase_31 AC 4 ms
4,348 KB
testcase_32 AC 4 ms
4,348 KB
testcase_33 AC 4 ms
4,348 KB
testcase_34 AC 4 ms
4,348 KB
testcase_35 AC 3 ms
4,348 KB
testcase_36 AC 3 ms
4,348 KB
testcase_37 AC 3 ms
4,348 KB
testcase_38 AC 4 ms
4,348 KB
testcase_39 AC 4 ms
4,348 KB
testcase_40 AC 4 ms
4,348 KB
testcase_41 AC 4 ms
4,348 KB
testcase_42 AC 4 ms
4,348 KB
testcase_43 AC 3 ms
4,348 KB
testcase_44 AC 4 ms
4,348 KB
testcase_45 AC 5 ms
4,416 KB
testcase_46 AC 3 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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]){
      |                ^

ソースコード

diff #

#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;
}
0