結果
| 問題 |
No.1709 Indistinguishable by MEX
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2021-10-16 18:54:11 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 24 ms / 2,000 ms |
| コード長 | 916 bytes |
| コンパイル時間 | 173 ms |
| コンパイル使用メモリ | 32,128 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-17 19:30:28 |
| 合計ジャッジ時間 | 1,600 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 26 |
ソースコード
/* -*- coding: utf-8 -*-
*
* 1709.cc: No.1709 Indistinguishable by MEX - yukicoder
*/
#include<cstdio>
using namespace std;
/* constant */
const int MAX_N = 200000;
const int MOD = 998244353;
/* typedef */
typedef long long ll;
/* global variables */
int as[MAX_N];
/* subroutines */
/* main */
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
int pi;
scanf("%d", &pi);
as[pi] = i;
}
//for (int i = 0; i < n; i++) printf("%d ", as[i]); putchar('\n');
int x = 1, l = as[0], r = as[0], k = 0;
//printf("0: [%d,%d] k=%d\n", l, r, k);
for (int i = 1; i < n; i++) {
int ai = as[i];
if (ai < l) {
k += l - ai - 1;
l = ai;
}
else if (r < ai) {
k += ai - r - 1;
r = ai;
}
else {
x = (ll)x * k % MOD;
k--;
}
//printf("%d: [%d,%d] k=%d\n", i, l, r, k);
}
printf("%d\n", x);
return 0;
}
tnakao0123