結果
問題 |
No.1709 Indistinguishable by MEX
|
ユーザー |
|
提出日時 | 2021-10-18 09:54:05 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 23 ms / 2,000 ms |
コード長 | 535 bytes |
コンパイル時間 | 552 ms |
コンパイル使用メモリ | 65,920 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-19 03:17:47 |
合計ジャッジ時間 | 3,088 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 |
ソースコード
#include <iostream> #include <algorithm> using namespace std; const long long md = 998244353; int p[200009]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; for (int i = 0; i < n; i++) { int a; cin >> a; p[a] = i; } int l = p[0], r = p[0], t = 0; long long ans = 1; for (int i = 1; i < n; i++) { if (p[i] < l) { t += l - p[i] - 1; l = p[i]; } else if (p[i] > r) { t += p[i] - r - 1; r = p[i]; } else { ans = (ans * t) % md; t--; } } cout << ans << '\n'; return 0; }