結果

問題 No.1294 マウンテン数列
ユーザー 沙耶花沙耶花
提出日時 2020-06-01 21:37:11
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 775 bytes
コンパイル時間 2,008 ms
コンパイル使用メモリ 200,452 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-18 01:37:08
合計ジャッジ時間 3,781 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 11 ms
4,376 KB
testcase_06 AC 14 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 72 ms
4,376 KB
testcase_11 AC 73 ms
4,380 KB
testcase_12 AC 73 ms
4,380 KB
testcase_13 AC 71 ms
4,380 KB
testcase_14 AC 59 ms
4,376 KB
testcase_15 AC 67 ms
4,376 KB
testcase_16 AC 59 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000000000

int get_ans(vector<int> &A,int d){
	vector<int> dp(A.size(),0);
	dp[1] = 1;
	int now = 0;
	for(int i=2;i<A.size();i++){
		while(d<A[now]-A[i]){
			now++;
		}
		if(now==i)return 0;
		dp[i] = mod(dp[i-1] - dp[now]);
		dp[i] = mod(dp[i] + dp[i-1]);
	}
	return dp.back();
}

int main(){
	
	int N;
	cin>>N;
	
	vector<int> A(N);
	for(int i=0;i<N;i++){
		cin>>A[i];
	}
	
	reverse(A.begin(),A.end());
	
	vector<int> num(A[0],0);
	for(int i=A[0]-A[1];i<A[0];i++){
		num[i] = get_ans(A,i);
	}
	
	int ans = 0;
	for(int i=1;i<A[0];i++){
		ans = mod(ans + mod(i*mod(num[i]-num[i-1])));
	}

	
	cout<<mod(2*ans)<<endl;
	
	return 0;
}
0