結果

問題 No.2717 Sum of Subarray of Subsequence
ユーザー 沙耶花沙耶花
提出日時 2024-04-05 21:54:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 718 bytes
コンパイル時間 4,166 ms
コンパイル使用メモリ 263,184 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-04-05 21:54:18
合計ジャッジ時間 4,992 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 AC 1 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 1 ms
6,676 KB
testcase_09 AC 29 ms
6,676 KB
testcase_10 AC 30 ms
6,676 KB
testcase_11 AC 31 ms
6,676 KB
testcase_12 AC 30 ms
6,676 KB
testcase_13 AC 29 ms
6,676 KB
testcase_14 AC 29 ms
6,676 KB
testcase_15 AC 30 ms
6,676 KB
testcase_16 AC 34 ms
6,676 KB
testcase_17 AC 31 ms
6,676 KB
testcase_18 AC 29 ms
6,676 KB
testcase_19 AC 29 ms
6,676 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 2 ms
6,676 KB
testcase_22 AC 28 ms
6,676 KB
testcase_23 AC 17 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 1000000000000000001

int main(){
	
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	
	int n;
	cin>>n;
	vector<long long> a(n);
	rep(i,n)cin>>a[i];
	
	vector<mint> dp(6,0);
	dp[0] = 1;
	rep(i,n){
		vector<mint> ndp(6,0);
		ndp[0] += dp[0];
		ndp[1] += dp[0] + dp[1];
		ndp[3] += dp[3] + (dp[0] + dp[1] + dp[2]) * a[i];
		ndp[4] += dp[3] + dp[4];
		rep(j,6)ndp[j] += dp[j];
		ndp[2] = 0;
		swap(dp,ndp);
	}
	
	mint ans = dp[3] + dp[4] + dp[5];
	cout<<ans.val()<<endl;
	
	
	return 0;
}
0