結果

問題 No.2275 →↑↓
ユーザー daiotadaiota
提出日時 2023-04-21 23:00:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 856 bytes
コンパイル時間 1,682 ms
コンパイル使用メモリ 162,940 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 09:03:09
合計ジャッジ時間 3,157 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 WA -
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 63 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;
#define REP(i,n) for(int i=0;i<int(n);i++)

const ll MOD=998244353;
ll a[200010];
ll extgcd(ll a,ll b,ll& x,ll& y){
	ll g;
	if(b!=0){
		g=extgcd(b,a%b,y,x);
		y-=(a/b)*x;
	}else{
                g=a;
		x=1; y=0;
	}
	  return g;
}

ll mod_inverse(ll a,ll m){
    ll x,y;
    extgcd(a,m,x,y);
    return (x%m+m)%m;
}



int main(void){
	cin.tie(nullptr);  ios_base::sync_with_stdio(false);
	int i,j,k;

	int N;
	cin >> N;
	for(i=1;i<=N;i++) cin >> a[i];

	ll ans=a[1];
	a[0]=1;
	for(i=2;i<=N;i++){
		if(a[i]>=a[i-1]){
			if(i==N){
				a[i]=a[i-1];
			}
			ans=a[i]*ans;
		    ans%=MOD;
		}else{
			ll v=mod_inverse(a[i-1],MOD);
			ans=ans*v;
			ans%=MOD;
			ans=ans*a[i-2];
			ans%=MOD;
			ans=ans*a[i];
			ans%=MOD;

		}
	}

	cout << ans << endl;


	return 0;
}
0