Submission #50005658


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long //instead of int main, use signed main
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef vector<int> vi;
const int MOD = 998244353;

signed main(){
    IOS;

    int N; cin >> N;
    vi a(N); for(int& i : a) cin >> i, i--;

    int ans = 1;
    vi vis(N);
    for(int i = 0, j = 0; i < N; i++){
        if(vis[a[i]] == 0) j++;
        if(i == a[i]) ans *= j, j--;
        vis[a[i]] = 1;
        if(a[i] < i) ans = 0;
        ans %= MOD;
    }
    for(int i = 0; i < N; i++) if(vis[i] && i != a[i]) ans = 0;
    cout << ans << endl;
}

Submission Info

Submission Time
Task B - Chmax
User lmlmlm
Language C++ 20 (gcc 12.2)
Score 600
Code Size 664 Byte
Status AC
Exec Time 13 ms
Memory 6312 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 52
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 02_corner_00.txt, 02_corner_01.txt, 02_corner_02.txt, 02_corner_03.txt, 03_hack_00.txt, 03_hack_01.txt, 03_hack_02.txt, 03_hack_03.txt, 03_hack_04.txt, 03_hack_05.txt, 03_hack_06.txt, 03_hack_07.txt, 03_hack_08.txt, 03_hack_09.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3432 KiB
00_sample_01.txt AC 1 ms 3460 KiB
00_sample_02.txt AC 1 ms 3468 KiB
01_random_00.txt AC 3 ms 3864 KiB
01_random_01.txt AC 3 ms 3784 KiB
01_random_02.txt AC 11 ms 6216 KiB
01_random_03.txt AC 12 ms 6156 KiB
01_random_04.txt AC 5 ms 4304 KiB
01_random_05.txt AC 5 ms 4368 KiB
01_random_06.txt AC 11 ms 6308 KiB
01_random_07.txt AC 12 ms 6164 KiB
01_random_08.txt AC 9 ms 5516 KiB
01_random_09.txt AC 9 ms 5416 KiB
01_random_10.txt AC 11 ms 6152 KiB
01_random_11.txt AC 12 ms 6208 KiB
01_random_12.txt AC 3 ms 3932 KiB
01_random_13.txt AC 3 ms 3836 KiB
01_random_14.txt AC 12 ms 6144 KiB
01_random_15.txt AC 11 ms 6144 KiB
01_random_16.txt AC 4 ms 4100 KiB
01_random_17.txt AC 4 ms 4096 KiB
01_random_18.txt AC 12 ms 6200 KiB
01_random_19.txt AC 11 ms 6172 KiB
01_random_20.txt AC 7 ms 4984 KiB
01_random_21.txt AC 7 ms 4988 KiB
01_random_22.txt AC 12 ms 6156 KiB
01_random_23.txt AC 11 ms 6200 KiB
01_random_24.txt AC 2 ms 3596 KiB
01_random_25.txt AC 2 ms 3516 KiB
01_random_26.txt AC 11 ms 6156 KiB
01_random_27.txt AC 11 ms 6168 KiB
01_random_28.txt AC 3 ms 3512 KiB
01_random_29.txt AC 3 ms 3516 KiB
01_random_30.txt AC 3 ms 3572 KiB
01_random_31.txt AC 13 ms 6172 KiB
01_random_32.txt AC 3 ms 3836 KiB
01_random_33.txt AC 12 ms 6172 KiB
01_random_34.txt AC 2 ms 3516 KiB
02_corner_00.txt AC 1 ms 3440 KiB
02_corner_01.txt AC 11 ms 6224 KiB
02_corner_02.txt AC 10 ms 6204 KiB
02_corner_03.txt AC 10 ms 6232 KiB
03_hack_00.txt AC 10 ms 6204 KiB
03_hack_01.txt AC 10 ms 6252 KiB
03_hack_02.txt AC 10 ms 6312 KiB
03_hack_03.txt AC 10 ms 6232 KiB
03_hack_04.txt AC 10 ms 6168 KiB
03_hack_05.txt AC 10 ms 6304 KiB
03_hack_06.txt AC 10 ms 6216 KiB
03_hack_07.txt AC 10 ms 6248 KiB
03_hack_08.txt AC 10 ms 6304 KiB
03_hack_09.txt AC 10 ms 6252 KiB