結果

問題 No.1709 Indistinguishable by MEX
ユーザー KKT89KKT89
提出日時 2022-07-05 01:42:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 150 ms / 2,000 ms
コード長 1,937 bytes
コンパイル時間 1,347 ms
コンパイル使用メモリ 123,916 KB
実行使用メモリ 14,208 KB
最終ジャッジ日時 2024-05-08 17:26:44
合計ジャッジ時間 4,425 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 112 ms
12,288 KB
testcase_09 AC 78 ms
10,752 KB
testcase_10 AC 73 ms
10,368 KB
testcase_11 AC 57 ms
8,960 KB
testcase_12 AC 57 ms
8,960 KB
testcase_13 AC 74 ms
11,520 KB
testcase_14 AC 68 ms
11,008 KB
testcase_15 AC 72 ms
11,264 KB
testcase_16 AC 97 ms
13,696 KB
testcase_17 AC 89 ms
13,056 KB
testcase_18 AC 150 ms
14,208 KB
testcase_19 AC 148 ms
14,208 KB
testcase_20 AC 147 ms
14,208 KB
testcase_21 AC 101 ms
14,208 KB
testcase_22 AC 100 ms
14,208 KB
testcase_23 AC 109 ms
14,208 KB
testcase_24 AC 108 ms
14,208 KB
testcase_25 AC 108 ms
14,208 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 56 ms
9,472 KB
testcase_28 AC 51 ms
8,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <sstream>
#include <utility>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <array>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}
inline double time() {
    return static_cast<long double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}

constexpr ll mod = 998244353;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int q; q = 1;
    while(q--){
        int n; cin >> n;
        ll res = 1;
        vector<int> a(n);
        vector<int> p(n);
        for(int i=0;i<n;i++){
            cin >> a[i];
            p[a[i]] = i;
        }
        int l = p[0], r = p[0];
        set<int> st;
        st.insert(0);
        ll cur = 0;
        for(int i=1;i<n;i++){
            if(st.find(i) != st.end()){
                res *= cur;
                res %= mod;
                cur--;
            }
            else{
                int id = p[i];
                if(id < l){
                    for(int j=id;j<l;j++){
                        cur++;
                        st.insert(a[j]);
                    }
                    l = id;
                }
                else{
                    for(int j=r+1;j<=id;j++){
                        cur++;
                        st.insert(a[j]);
                    }
                    r = id;
                }
                cur--;
            }
        }
        cout << res << "\n";
    }
}
0