結果

問題 No.1709 Indistinguishable by MEX
ユーザー 夜
提出日時 2021-10-16 01:52:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 74 ms / 2,000 ms
コード長 864 bytes
コンパイル時間 796 ms
コンパイル使用メモリ 94,060 KB
実行使用メモリ 5,164 KB
最終ジャッジ日時 2023-10-17 22:00:55
合計ジャッジ時間 3,080 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 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 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 60 ms
4,884 KB
testcase_09 AC 47 ms
4,652 KB
testcase_10 AC 45 ms
4,600 KB
testcase_11 AC 36 ms
4,420 KB
testcase_12 AC 33 ms
4,396 KB
testcase_13 AC 49 ms
4,780 KB
testcase_14 AC 45 ms
4,684 KB
testcase_15 AC 48 ms
4,752 KB
testcase_16 AC 64 ms
5,100 KB
testcase_17 AC 59 ms
4,984 KB
testcase_18 AC 73 ms
5,164 KB
testcase_19 AC 74 ms
5,164 KB
testcase_20 AC 74 ms
5,164 KB
testcase_21 AC 68 ms
5,164 KB
testcase_22 AC 67 ms
5,164 KB
testcase_23 AC 63 ms
5,164 KB
testcase_24 AC 62 ms
5,164 KB
testcase_25 AC 62 ms
5,164 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 34 ms
4,468 KB
testcase_28 AC 30 ms
4,400 KB
権限があれば一括ダウンロードができます

ソースコード

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