結果

問題 No.1709 Indistinguishable by MEX
ユーザー
提出日時 2021-10-16 01:52:08
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 864 bytes
コンパイル時間 1,182 ms
コンパイル使用メモリ 94,988 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-17 19:15:17
合計ジャッジ時間 3,411 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
#include <fstream>
using namespace std;
long long in[200020];
long long mod = 998244353;
int main() {
	long long n;
	cin >> n;
	if (n == 1) {
		cout << 1 << endl;
		return 0;
	}
	for (int i = 0; i < n; i++) {
		int p;
		cin >> p;
		in[p] = i;
	}
	long long l = in[0], r = in[1];
	if (l > r) {
		swap(l, r);
	}
	long long ans = 1;
	long long now = r - l - 1;
	for (int i = 2; i < n; i++) {
		if (in[i] < l) {
			now += l - in[i] - 1;
			l = in[i];
		}
		else if (in[i] > r) {
			now += in[i] - r - 1;
			r = in[i];
		}
		else {
			ans *= now;
			now--;
			ans %= mod;
		}
	}
	cout << ans << endl;
}
0