Submission #1026368

# Submission time Handle Problem Language Result Execution time Memory
1026368 2024-07-18T02:59:23 Z Whisper Binaria (CCO23_day1problem1) C++17
25 / 25
243 ms 115284 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define int long long
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (b); i >= (a); i --)
#define REP(i, n) for (int i = 0; i < (a); ++i)
#define REPD(i, n) for (int i = (a) - 1; i >= 0; --i)

#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)


constexpr ll LINF = (1ll << 60);
constexpr int INF = (1ll << 30);
constexpr int Mod = 1e6 + 3;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

/*
    Phu Trong from Nguyen Tat Thanh High School for gifted student
*/

template <class X, class Y>
    bool minimize(X &x, const Y &y){
        X eps = 1e-9;
        if (x > y + eps) {x = y; return 1;}
        return 0;
    }

template <class X, class Y>
    bool maximize(X &x, const Y &y){
        X eps = 1e-9;
        if (x + eps < y) {x = y; return 1;}
        return 0;
    }
#define MAX         1000005

int N, K, M;
int A[MAX];


int inv[MAX], fac[MAX];
int power(int a, int exp){
    int res = 1;
    for (;exp > 0; a = (a * a) % Mod, exp >>= 1) if(exp & 1){
        res = (res * a) % Mod;
    }
    return res;
}
void genFac(int n){
    fac[0] = 1;
    for (int i = 1; i <= n; ++i) fac[i] = fac[i - 1] * i % Mod;
    inv[n] = power(fac[n], Mod - 2);
    for (int i = n - 1; i >= 0; --i) inv[i] = inv[i + 1] * (i + 1) % Mod;
}

int C(int n, int k){
    if (n < k || k < 0) return 0;
    return fac[n] * inv[k] % Mod * inv[n - k] % Mod;
}
void mul(int &x, int y){
    x = (1ll * x * y) % Mod;
}
void add(int &x, int y){
    x += y;
    if (x >= Mod) x -= Mod;
}

vector<int> G[MAX];

int col[MAX];
int vis[MAX];
void paint(int u, int c){
    vis[u] = 1; col[u] = c;
    for (int&v : G[u]) if(!vis[v]){
        paint(v, c);
    }
}
void process(void){
    cin >> N >> K;
    M = N - K + 1;
    for (int i = 1; i <= M; ++i) cin >> A[i];
    genFac(N);
    for (int i = 1; i <= N; ++i) col[i] = -1;
    for (int i = 1; i < M; ++i){
        if(A[i] == A[i + 1]){
            G[i].push_back(i + K);
            G[i + K].push_back(i);
        }
        else if(A[i] + 1 == A[i + 1]){
            col[i] = 0, col[i + K] = 1;
        }
        else if(A[i] - 1 == A[i + 1]){
            col[i] = 1, col[i + K] = 0;
        }
        else return void(cout << 0);
    }
    vector<int> vis(K + 5);
    for (int i = 1; i <= N; ++i){
        if (~col[i]){
            paint(i, col[i]);
        }
    }
    for (int i = 1; i < M; ++i){
        if (A[i] == A[i + 1]){
            if(col[i] != col[i + K]) return void(cout << 0);
        }
        else if (A[i] < A[i + 1]) {
            if(!(col[i] == 0 && col[i + K] == 1)) return void(cout << 0);
        }
        else{
            if(!(col[i] == 1 && col[i + K] == 0)) return void(cout << 0);
        }
    }

    int need = A[1], emp = 0;
    for (int i = 1; i <= K; ++i){
        if (col[i] == -1) emp++;
        else if(col[i] == 1) need--;
    }

    assert(emp >= 0);
    cout << C(emp, need);
}
signed main(){
    #define name "Whisper"
    cin.tie(nullptr) -> sync_with_stdio(false);
    //freopen(name".inp", "r", stdin);
    //freopen(name".out", "w", stdout);
    process();
    return (0 ^ 0);
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 31068 KB Output is correct
2 Correct 4 ms 31068 KB Output is correct
3 Correct 5 ms 31240 KB Output is correct
4 Correct 4 ms 31488 KB Output is correct
5 Correct 6 ms 31064 KB Output is correct
6 Correct 5 ms 31068 KB Output is correct
7 Correct 4 ms 31064 KB Output is correct
8 Correct 5 ms 31320 KB Output is correct
9 Correct 5 ms 31320 KB Output is correct
10 Correct 4 ms 31068 KB Output is correct
11 Correct 4 ms 31068 KB Output is correct
12 Correct 5 ms 31068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 31068 KB Output is correct
2 Correct 4 ms 31068 KB Output is correct
3 Correct 5 ms 31240 KB Output is correct
4 Correct 4 ms 31488 KB Output is correct
5 Correct 6 ms 31064 KB Output is correct
6 Correct 5 ms 31068 KB Output is correct
7 Correct 4 ms 31064 KB Output is correct
8 Correct 5 ms 31320 KB Output is correct
9 Correct 5 ms 31320 KB Output is correct
10 Correct 4 ms 31068 KB Output is correct
11 Correct 4 ms 31068 KB Output is correct
12 Correct 5 ms 31068 KB Output is correct
13 Correct 5 ms 31068 KB Output is correct
14 Correct 5 ms 31068 KB Output is correct
15 Correct 5 ms 31068 KB Output is correct
16 Correct 5 ms 31068 KB Output is correct
17 Correct 4 ms 31068 KB Output is correct
18 Correct 5 ms 31252 KB Output is correct
19 Correct 5 ms 31064 KB Output is correct
20 Correct 5 ms 31176 KB Output is correct
21 Correct 4 ms 31252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 31068 KB Output is correct
2 Correct 4 ms 31068 KB Output is correct
3 Correct 5 ms 31240 KB Output is correct
4 Correct 4 ms 31488 KB Output is correct
5 Correct 6 ms 31064 KB Output is correct
6 Correct 5 ms 31068 KB Output is correct
7 Correct 4 ms 31064 KB Output is correct
8 Correct 5 ms 31320 KB Output is correct
9 Correct 5 ms 31320 KB Output is correct
10 Correct 4 ms 31068 KB Output is correct
11 Correct 4 ms 31068 KB Output is correct
12 Correct 5 ms 31068 KB Output is correct
13 Correct 5 ms 31068 KB Output is correct
14 Correct 5 ms 31068 KB Output is correct
15 Correct 5 ms 31068 KB Output is correct
16 Correct 5 ms 31068 KB Output is correct
17 Correct 4 ms 31068 KB Output is correct
18 Correct 5 ms 31252 KB Output is correct
19 Correct 5 ms 31064 KB Output is correct
20 Correct 5 ms 31176 KB Output is correct
21 Correct 4 ms 31252 KB Output is correct
22 Correct 5 ms 31068 KB Output is correct
23 Correct 5 ms 31160 KB Output is correct
24 Correct 5 ms 31068 KB Output is correct
25 Correct 5 ms 31068 KB Output is correct
26 Correct 5 ms 31196 KB Output is correct
27 Correct 5 ms 31068 KB Output is correct
28 Correct 5 ms 31068 KB Output is correct
29 Correct 5 ms 31068 KB Output is correct
30 Correct 5 ms 31184 KB Output is correct
31 Correct 5 ms 31236 KB Output is correct
32 Correct 5 ms 31068 KB Output is correct
33 Correct 5 ms 31324 KB Output is correct
34 Correct 4 ms 31068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 31068 KB Output is correct
2 Correct 4 ms 31068 KB Output is correct
3 Correct 5 ms 31240 KB Output is correct
4 Correct 4 ms 31488 KB Output is correct
5 Correct 6 ms 31064 KB Output is correct
6 Correct 5 ms 31068 KB Output is correct
7 Correct 4 ms 31064 KB Output is correct
8 Correct 5 ms 31320 KB Output is correct
9 Correct 5 ms 31320 KB Output is correct
10 Correct 4 ms 31068 KB Output is correct
11 Correct 4 ms 31068 KB Output is correct
12 Correct 5 ms 31068 KB Output is correct
13 Correct 5 ms 31068 KB Output is correct
14 Correct 5 ms 31068 KB Output is correct
15 Correct 5 ms 31068 KB Output is correct
16 Correct 5 ms 31068 KB Output is correct
17 Correct 4 ms 31068 KB Output is correct
18 Correct 5 ms 31252 KB Output is correct
19 Correct 5 ms 31064 KB Output is correct
20 Correct 5 ms 31176 KB Output is correct
21 Correct 4 ms 31252 KB Output is correct
22 Correct 5 ms 31068 KB Output is correct
23 Correct 5 ms 31160 KB Output is correct
24 Correct 5 ms 31068 KB Output is correct
25 Correct 5 ms 31068 KB Output is correct
26 Correct 5 ms 31196 KB Output is correct
27 Correct 5 ms 31068 KB Output is correct
28 Correct 5 ms 31068 KB Output is correct
29 Correct 5 ms 31068 KB Output is correct
30 Correct 5 ms 31184 KB Output is correct
31 Correct 5 ms 31236 KB Output is correct
32 Correct 5 ms 31068 KB Output is correct
33 Correct 5 ms 31324 KB Output is correct
34 Correct 4 ms 31068 KB Output is correct
35 Correct 105 ms 89936 KB Output is correct
36 Correct 187 ms 95572 KB Output is correct
37 Correct 180 ms 96852 KB Output is correct
38 Correct 122 ms 97852 KB Output is correct
39 Correct 100 ms 89936 KB Output is correct
40 Correct 109 ms 90964 KB Output is correct
41 Correct 243 ms 97412 KB Output is correct
42 Correct 122 ms 96376 KB Output is correct
43 Correct 124 ms 96848 KB Output is correct
44 Correct 104 ms 89936 KB Output is correct
45 Correct 124 ms 115284 KB Output is correct
46 Correct 102 ms 89936 KB Output is correct
47 Correct 101 ms 89936 KB Output is correct
48 Correct 125 ms 90964 KB Output is correct
49 Correct 122 ms 98128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 31068 KB Output is correct
2 Correct 4 ms 31068 KB Output is correct
3 Correct 5 ms 31240 KB Output is correct
4 Correct 4 ms 31488 KB Output is correct
5 Correct 6 ms 31064 KB Output is correct
6 Correct 5 ms 31068 KB Output is correct
7 Correct 4 ms 31064 KB Output is correct
8 Correct 5 ms 31320 KB Output is correct
9 Correct 5 ms 31320 KB Output is correct
10 Correct 4 ms 31068 KB Output is correct
11 Correct 4 ms 31068 KB Output is correct
12 Correct 5 ms 31068 KB Output is correct
13 Correct 5 ms 31068 KB Output is correct
14 Correct 5 ms 31068 KB Output is correct
15 Correct 5 ms 31068 KB Output is correct
16 Correct 5 ms 31068 KB Output is correct
17 Correct 4 ms 31068 KB Output is correct
18 Correct 5 ms 31252 KB Output is correct
19 Correct 5 ms 31064 KB Output is correct
20 Correct 5 ms 31176 KB Output is correct
21 Correct 4 ms 31252 KB Output is correct
22 Correct 5 ms 31068 KB Output is correct
23 Correct 5 ms 31160 KB Output is correct
24 Correct 5 ms 31068 KB Output is correct
25 Correct 5 ms 31068 KB Output is correct
26 Correct 5 ms 31196 KB Output is correct
27 Correct 5 ms 31068 KB Output is correct
28 Correct 5 ms 31068 KB Output is correct
29 Correct 5 ms 31068 KB Output is correct
30 Correct 5 ms 31184 KB Output is correct
31 Correct 5 ms 31236 KB Output is correct
32 Correct 5 ms 31068 KB Output is correct
33 Correct 5 ms 31324 KB Output is correct
34 Correct 4 ms 31068 KB Output is correct
35 Correct 105 ms 89936 KB Output is correct
36 Correct 187 ms 95572 KB Output is correct
37 Correct 180 ms 96852 KB Output is correct
38 Correct 122 ms 97852 KB Output is correct
39 Correct 100 ms 89936 KB Output is correct
40 Correct 109 ms 90964 KB Output is correct
41 Correct 243 ms 97412 KB Output is correct
42 Correct 122 ms 96376 KB Output is correct
43 Correct 124 ms 96848 KB Output is correct
44 Correct 104 ms 89936 KB Output is correct
45 Correct 124 ms 115284 KB Output is correct
46 Correct 102 ms 89936 KB Output is correct
47 Correct 101 ms 89936 KB Output is correct
48 Correct 125 ms 90964 KB Output is correct
49 Correct 122 ms 98128 KB Output is correct
50 Correct 117 ms 92752 KB Output is correct
51 Correct 113 ms 92756 KB Output is correct
52 Correct 144 ms 99152 KB Output is correct
53 Correct 184 ms 96852 KB Output is correct
54 Correct 135 ms 99052 KB Output is correct
55 Correct 118 ms 99152 KB Output is correct
56 Correct 125 ms 99408 KB Output is correct
57 Correct 167 ms 96852 KB Output is correct
58 Correct 119 ms 92788 KB Output is correct
59 Correct 154 ms 98668 KB Output is correct
60 Correct 178 ms 96876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 31068 KB Output is correct
2 Correct 4 ms 31068 KB Output is correct
3 Correct 5 ms 31240 KB Output is correct
4 Correct 4 ms 31488 KB Output is correct
5 Correct 6 ms 31064 KB Output is correct
6 Correct 5 ms 31068 KB Output is correct
7 Correct 4 ms 31064 KB Output is correct
8 Correct 5 ms 31320 KB Output is correct
9 Correct 5 ms 31320 KB Output is correct
10 Correct 4 ms 31068 KB Output is correct
11 Correct 4 ms 31068 KB Output is correct
12 Correct 5 ms 31068 KB Output is correct
13 Correct 5 ms 31068 KB Output is correct
14 Correct 5 ms 31068 KB Output is correct
15 Correct 5 ms 31068 KB Output is correct
16 Correct 5 ms 31068 KB Output is correct
17 Correct 4 ms 31068 KB Output is correct
18 Correct 5 ms 31252 KB Output is correct
19 Correct 5 ms 31064 KB Output is correct
20 Correct 5 ms 31176 KB Output is correct
21 Correct 4 ms 31252 KB Output is correct
22 Correct 5 ms 31068 KB Output is correct
23 Correct 5 ms 31160 KB Output is correct
24 Correct 5 ms 31068 KB Output is correct
25 Correct 5 ms 31068 KB Output is correct
26 Correct 5 ms 31196 KB Output is correct
27 Correct 5 ms 31068 KB Output is correct
28 Correct 5 ms 31068 KB Output is correct
29 Correct 5 ms 31068 KB Output is correct
30 Correct 5 ms 31184 KB Output is correct
31 Correct 5 ms 31236 KB Output is correct
32 Correct 5 ms 31068 KB Output is correct
33 Correct 5 ms 31324 KB Output is correct
34 Correct 4 ms 31068 KB Output is correct
35 Correct 105 ms 89936 KB Output is correct
36 Correct 187 ms 95572 KB Output is correct
37 Correct 180 ms 96852 KB Output is correct
38 Correct 122 ms 97852 KB Output is correct
39 Correct 100 ms 89936 KB Output is correct
40 Correct 109 ms 90964 KB Output is correct
41 Correct 243 ms 97412 KB Output is correct
42 Correct 122 ms 96376 KB Output is correct
43 Correct 124 ms 96848 KB Output is correct
44 Correct 104 ms 89936 KB Output is correct
45 Correct 124 ms 115284 KB Output is correct
46 Correct 102 ms 89936 KB Output is correct
47 Correct 101 ms 89936 KB Output is correct
48 Correct 125 ms 90964 KB Output is correct
49 Correct 122 ms 98128 KB Output is correct
50 Correct 117 ms 92752 KB Output is correct
51 Correct 113 ms 92756 KB Output is correct
52 Correct 144 ms 99152 KB Output is correct
53 Correct 184 ms 96852 KB Output is correct
54 Correct 135 ms 99052 KB Output is correct
55 Correct 118 ms 99152 KB Output is correct
56 Correct 125 ms 99408 KB Output is correct
57 Correct 167 ms 96852 KB Output is correct
58 Correct 119 ms 92788 KB Output is correct
59 Correct 154 ms 98668 KB Output is correct
60 Correct 178 ms 96876 KB Output is correct
61 Correct 21 ms 57368 KB Output is correct
62 Correct 19 ms 57432 KB Output is correct
63 Correct 20 ms 57436 KB Output is correct
64 Correct 20 ms 57432 KB Output is correct
65 Correct 88 ms 97352 KB Output is correct
66 Correct 61 ms 82768 KB Output is correct
67 Correct 131 ms 96596 KB Output is correct
68 Correct 31 ms 64856 KB Output is correct
69 Correct 19 ms 57436 KB Output is correct
70 Correct 19 ms 57384 KB Output is correct
71 Correct 19 ms 57436 KB Output is correct