結果
| 問題 |
No.1709 Indistinguishable by MEX
|
| コンテスト | |
| ユーザー |
SSRS
|
| 提出日時 | 2021-10-15 21:35:36 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 57 ms / 2,000 ms |
| コード長 | 566 bytes |
| コンパイル時間 | 1,358 ms |
| コンパイル使用メモリ | 168,668 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-17 17:17:34 |
| 合計ジャッジ時間 | 3,337 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 26 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
int main(){
int N;
cin >> N;
vector<int> P(N);
for (int i = 0; i < N; i++){
cin >> P[i];
}
vector<int> Q(N);
for (int i = 0; i < N; i++){
Q[P[i]] = i;
}
int L = Q[0], R = Q[0];
int c = 0;
long long ans = 1;
for (int i = 1; i < N; i++){
if (Q[i] < L){
c += L - Q[i] - 1;
L = Q[i];
} else if (Q[i] > R){
c += Q[i] - R - 1;
R = Q[i];
} else {
ans *= c;
ans %= MOD;
c--;
}
}
cout << ans << endl;
}
SSRS