Submission #1027555

# Submission time Handle Problem Language Result Execution time Memory
1027555 2024-07-19T07:31:02 Z anHiep Binaria (CCO23_day1problem1) C++14
25 / 25
228 ms 125592 KB
#include<bits/stdc++.h>
#ifdef LOCAL
#include "D:\debug.h"
#else
#define cebug(...) "Orz_chUoNgnn_khanhtb_0x2ee08"
#endif

using namespace std;

#define int long long
#define fi first 
#define se second
#define pb push_back
#define ll long long
#define ii pair<int, int>
#define vi vector<int> 
#define vll vector<ll>
#define vii vector<ii>
#define cd complex<double>
const ll mod = 1e6 + 3;
const ll INF = 1e18L + 5;
const double PI = acos(-1);
const int block = 320;
const int N = 1e6;
int tc, tt = 1;

int n, k;
ll a[N + 5], b[N + 5];
vi g[N + 5];
int vis[N + 5];

ll powmod(ll a, ll b) {
    ll ans = 1;
    while(b) {
        if(b & 1) ans = ans * a % mod;
        a = a * a % mod;
        b /= 2;
    }
    return ans;
}

void dfs(int root, int u, int par) {
    b[u] = b[root];
    vis[u] = true;
    for(auto v: g[u])
        if(!vis[v]) dfs(root, v, u);
}

void solve() {
    cin>>n>>k;
    memset(b, -1, sizeof(b));
    for(int i=1; i<=n-k+1; i++) 
        cin>>a[i];
    for(int i=2; i<=n-k+1; i++) {
        if(abs(a[i] - a[i - 1]) > 1) {
            cout<<0<<'\n';
            return;
        }
        if(a[i] == a[i - 1]) {
            g[i + k - 1].pb(i - 1);
            g[i - 1].pb(i + k - 1);
        }
        if(a[i] > a[i - 1]) {
            if(b[i - 1] == 1 || b[i + k - 1] == 0) {
                cout<<0<<'\n';
                return;
            }
            b[i - 1] = 0;
            b[i + k - 1] = 1;
        }
        if(a[i] < a[i - 1]) {
            if(b[i - 1] == 0 || b[i + k - 1] == 1) {
                cout<<0<<'\n';
                return;
            }
            b[i - 1] = 1;
            b[i + k - 1] = 0;
        }
    }
    for(int i=1; i<=n; i++)
        if(b[i] != -1 && !vis[i]) dfs(i, i, -1); 
    ll ans = 1, sum = 0, cnt = 0;
    for(int i=1; i<=k; i++) {
        if(b[i] == -1) cnt++;
        else sum += b[i]; 
    }
    if(sum > a[1] || a[1] - sum > cnt) {
        cout<<0<<'\n';
        return;
    }
    sum = a[1] - sum;
    for(int i=cnt; i>=cnt - sum + 1; i--) ans = ans * i % mod;
    ll dem = 1;
    for(int i=1; i<=sum; i++) dem = dem * i % mod;
    ans = ans * powmod(dem, mod - 2) % mod; 
    cout<<ans;
}
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    for(tc=1; tc<=tt; tc++) solve();
    cerr<<"\nTime elapsed: "<<1000.0*clock()/CLOCKS_PER_SEC<<" ms.\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 33112 KB Output is correct
2 Correct 5 ms 33116 KB Output is correct
3 Correct 5 ms 33116 KB Output is correct
4 Correct 5 ms 33248 KB Output is correct
5 Correct 5 ms 33244 KB Output is correct
6 Correct 5 ms 33116 KB Output is correct
7 Correct 5 ms 33116 KB Output is correct
8 Correct 5 ms 33116 KB Output is correct
9 Correct 5 ms 33116 KB Output is correct
10 Correct 4 ms 33116 KB Output is correct
11 Correct 5 ms 33116 KB Output is correct
12 Correct 5 ms 33116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 33112 KB Output is correct
2 Correct 5 ms 33116 KB Output is correct
3 Correct 5 ms 33116 KB Output is correct
4 Correct 5 ms 33248 KB Output is correct
5 Correct 5 ms 33244 KB Output is correct
6 Correct 5 ms 33116 KB Output is correct
7 Correct 5 ms 33116 KB Output is correct
8 Correct 5 ms 33116 KB Output is correct
9 Correct 5 ms 33116 KB Output is correct
10 Correct 4 ms 33116 KB Output is correct
11 Correct 5 ms 33116 KB Output is correct
12 Correct 5 ms 33116 KB Output is correct
13 Correct 5 ms 33116 KB Output is correct
14 Correct 4 ms 33200 KB Output is correct
15 Correct 4 ms 33116 KB Output is correct
16 Correct 4 ms 33232 KB Output is correct
17 Correct 5 ms 33116 KB Output is correct
18 Correct 5 ms 33112 KB Output is correct
19 Correct 5 ms 33116 KB Output is correct
20 Correct 5 ms 33116 KB Output is correct
21 Correct 5 ms 33116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 33112 KB Output is correct
2 Correct 5 ms 33116 KB Output is correct
3 Correct 5 ms 33116 KB Output is correct
4 Correct 5 ms 33248 KB Output is correct
5 Correct 5 ms 33244 KB Output is correct
6 Correct 5 ms 33116 KB Output is correct
7 Correct 5 ms 33116 KB Output is correct
8 Correct 5 ms 33116 KB Output is correct
9 Correct 5 ms 33116 KB Output is correct
10 Correct 4 ms 33116 KB Output is correct
11 Correct 5 ms 33116 KB Output is correct
12 Correct 5 ms 33116 KB Output is correct
13 Correct 5 ms 33116 KB Output is correct
14 Correct 4 ms 33200 KB Output is correct
15 Correct 4 ms 33116 KB Output is correct
16 Correct 4 ms 33232 KB Output is correct
17 Correct 5 ms 33116 KB Output is correct
18 Correct 5 ms 33112 KB Output is correct
19 Correct 5 ms 33116 KB Output is correct
20 Correct 5 ms 33116 KB Output is correct
21 Correct 5 ms 33116 KB Output is correct
22 Correct 5 ms 33116 KB Output is correct
23 Correct 5 ms 33116 KB Output is correct
24 Correct 4 ms 33116 KB Output is correct
25 Correct 5 ms 33116 KB Output is correct
26 Correct 5 ms 33116 KB Output is correct
27 Correct 6 ms 33284 KB Output is correct
28 Correct 5 ms 33116 KB Output is correct
29 Correct 5 ms 33116 KB Output is correct
30 Correct 5 ms 33116 KB Output is correct
31 Correct 4 ms 33116 KB Output is correct
32 Correct 4 ms 33116 KB Output is correct
33 Correct 5 ms 33116 KB Output is correct
34 Correct 5 ms 33116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 33112 KB Output is correct
2 Correct 5 ms 33116 KB Output is correct
3 Correct 5 ms 33116 KB Output is correct
4 Correct 5 ms 33248 KB Output is correct
5 Correct 5 ms 33244 KB Output is correct
6 Correct 5 ms 33116 KB Output is correct
7 Correct 5 ms 33116 KB Output is correct
8 Correct 5 ms 33116 KB Output is correct
9 Correct 5 ms 33116 KB Output is correct
10 Correct 4 ms 33116 KB Output is correct
11 Correct 5 ms 33116 KB Output is correct
12 Correct 5 ms 33116 KB Output is correct
13 Correct 5 ms 33116 KB Output is correct
14 Correct 4 ms 33200 KB Output is correct
15 Correct 4 ms 33116 KB Output is correct
16 Correct 4 ms 33232 KB Output is correct
17 Correct 5 ms 33116 KB Output is correct
18 Correct 5 ms 33112 KB Output is correct
19 Correct 5 ms 33116 KB Output is correct
20 Correct 5 ms 33116 KB Output is correct
21 Correct 5 ms 33116 KB Output is correct
22 Correct 5 ms 33116 KB Output is correct
23 Correct 5 ms 33116 KB Output is correct
24 Correct 4 ms 33116 KB Output is correct
25 Correct 5 ms 33116 KB Output is correct
26 Correct 5 ms 33116 KB Output is correct
27 Correct 6 ms 33284 KB Output is correct
28 Correct 5 ms 33116 KB Output is correct
29 Correct 5 ms 33116 KB Output is correct
30 Correct 5 ms 33116 KB Output is correct
31 Correct 4 ms 33116 KB Output is correct
32 Correct 4 ms 33116 KB Output is correct
33 Correct 5 ms 33116 KB Output is correct
34 Correct 5 ms 33116 KB Output is correct
35 Correct 103 ms 72308 KB Output is correct
36 Correct 192 ms 78616 KB Output is correct
37 Correct 180 ms 79696 KB Output is correct
38 Correct 115 ms 80644 KB Output is correct
39 Correct 98 ms 72276 KB Output is correct
40 Correct 104 ms 72412 KB Output is correct
41 Correct 206 ms 80208 KB Output is correct
42 Correct 118 ms 80976 KB Output is correct
43 Correct 115 ms 80812 KB Output is correct
44 Correct 102 ms 72460 KB Output is correct
45 Correct 138 ms 125592 KB Output is correct
46 Correct 91 ms 72272 KB Output is correct
47 Correct 108 ms 72276 KB Output is correct
48 Correct 141 ms 72276 KB Output is correct
49 Correct 113 ms 80904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 33112 KB Output is correct
2 Correct 5 ms 33116 KB Output is correct
3 Correct 5 ms 33116 KB Output is correct
4 Correct 5 ms 33248 KB Output is correct
5 Correct 5 ms 33244 KB Output is correct
6 Correct 5 ms 33116 KB Output is correct
7 Correct 5 ms 33116 KB Output is correct
8 Correct 5 ms 33116 KB Output is correct
9 Correct 5 ms 33116 KB Output is correct
10 Correct 4 ms 33116 KB Output is correct
11 Correct 5 ms 33116 KB Output is correct
12 Correct 5 ms 33116 KB Output is correct
13 Correct 5 ms 33116 KB Output is correct
14 Correct 4 ms 33200 KB Output is correct
15 Correct 4 ms 33116 KB Output is correct
16 Correct 4 ms 33232 KB Output is correct
17 Correct 5 ms 33116 KB Output is correct
18 Correct 5 ms 33112 KB Output is correct
19 Correct 5 ms 33116 KB Output is correct
20 Correct 5 ms 33116 KB Output is correct
21 Correct 5 ms 33116 KB Output is correct
22 Correct 5 ms 33116 KB Output is correct
23 Correct 5 ms 33116 KB Output is correct
24 Correct 4 ms 33116 KB Output is correct
25 Correct 5 ms 33116 KB Output is correct
26 Correct 5 ms 33116 KB Output is correct
27 Correct 6 ms 33284 KB Output is correct
28 Correct 5 ms 33116 KB Output is correct
29 Correct 5 ms 33116 KB Output is correct
30 Correct 5 ms 33116 KB Output is correct
31 Correct 4 ms 33116 KB Output is correct
32 Correct 4 ms 33116 KB Output is correct
33 Correct 5 ms 33116 KB Output is correct
34 Correct 5 ms 33116 KB Output is correct
35 Correct 103 ms 72308 KB Output is correct
36 Correct 192 ms 78616 KB Output is correct
37 Correct 180 ms 79696 KB Output is correct
38 Correct 115 ms 80644 KB Output is correct
39 Correct 98 ms 72276 KB Output is correct
40 Correct 104 ms 72412 KB Output is correct
41 Correct 206 ms 80208 KB Output is correct
42 Correct 118 ms 80976 KB Output is correct
43 Correct 115 ms 80812 KB Output is correct
44 Correct 102 ms 72460 KB Output is correct
45 Correct 138 ms 125592 KB Output is correct
46 Correct 91 ms 72272 KB Output is correct
47 Correct 108 ms 72276 KB Output is correct
48 Correct 141 ms 72276 KB Output is correct
49 Correct 113 ms 80904 KB Output is correct
50 Correct 102 ms 72276 KB Output is correct
51 Correct 102 ms 72276 KB Output is correct
52 Correct 134 ms 78344 KB Output is correct
53 Correct 228 ms 76368 KB Output is correct
54 Correct 139 ms 78348 KB Output is correct
55 Correct 118 ms 78596 KB Output is correct
56 Correct 130 ms 78552 KB Output is correct
57 Correct 191 ms 77308 KB Output is correct
58 Correct 112 ms 72196 KB Output is correct
59 Correct 142 ms 78084 KB Output is correct
60 Correct 148 ms 77424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 33112 KB Output is correct
2 Correct 5 ms 33116 KB Output is correct
3 Correct 5 ms 33116 KB Output is correct
4 Correct 5 ms 33248 KB Output is correct
5 Correct 5 ms 33244 KB Output is correct
6 Correct 5 ms 33116 KB Output is correct
7 Correct 5 ms 33116 KB Output is correct
8 Correct 5 ms 33116 KB Output is correct
9 Correct 5 ms 33116 KB Output is correct
10 Correct 4 ms 33116 KB Output is correct
11 Correct 5 ms 33116 KB Output is correct
12 Correct 5 ms 33116 KB Output is correct
13 Correct 5 ms 33116 KB Output is correct
14 Correct 4 ms 33200 KB Output is correct
15 Correct 4 ms 33116 KB Output is correct
16 Correct 4 ms 33232 KB Output is correct
17 Correct 5 ms 33116 KB Output is correct
18 Correct 5 ms 33112 KB Output is correct
19 Correct 5 ms 33116 KB Output is correct
20 Correct 5 ms 33116 KB Output is correct
21 Correct 5 ms 33116 KB Output is correct
22 Correct 5 ms 33116 KB Output is correct
23 Correct 5 ms 33116 KB Output is correct
24 Correct 4 ms 33116 KB Output is correct
25 Correct 5 ms 33116 KB Output is correct
26 Correct 5 ms 33116 KB Output is correct
27 Correct 6 ms 33284 KB Output is correct
28 Correct 5 ms 33116 KB Output is correct
29 Correct 5 ms 33116 KB Output is correct
30 Correct 5 ms 33116 KB Output is correct
31 Correct 4 ms 33116 KB Output is correct
32 Correct 4 ms 33116 KB Output is correct
33 Correct 5 ms 33116 KB Output is correct
34 Correct 5 ms 33116 KB Output is correct
35 Correct 103 ms 72308 KB Output is correct
36 Correct 192 ms 78616 KB Output is correct
37 Correct 180 ms 79696 KB Output is correct
38 Correct 115 ms 80644 KB Output is correct
39 Correct 98 ms 72276 KB Output is correct
40 Correct 104 ms 72412 KB Output is correct
41 Correct 206 ms 80208 KB Output is correct
42 Correct 118 ms 80976 KB Output is correct
43 Correct 115 ms 80812 KB Output is correct
44 Correct 102 ms 72460 KB Output is correct
45 Correct 138 ms 125592 KB Output is correct
46 Correct 91 ms 72272 KB Output is correct
47 Correct 108 ms 72276 KB Output is correct
48 Correct 141 ms 72276 KB Output is correct
49 Correct 113 ms 80904 KB Output is correct
50 Correct 102 ms 72276 KB Output is correct
51 Correct 102 ms 72276 KB Output is correct
52 Correct 134 ms 78344 KB Output is correct
53 Correct 228 ms 76368 KB Output is correct
54 Correct 139 ms 78348 KB Output is correct
55 Correct 118 ms 78596 KB Output is correct
56 Correct 130 ms 78552 KB Output is correct
57 Correct 191 ms 77308 KB Output is correct
58 Correct 112 ms 72196 KB Output is correct
59 Correct 142 ms 78084 KB Output is correct
60 Correct 148 ms 77424 KB Output is correct
61 Correct 9 ms 33116 KB Output is correct
62 Correct 10 ms 33288 KB Output is correct
63 Correct 12 ms 33116 KB Output is correct
64 Correct 9 ms 33200 KB Output is correct
65 Correct 82 ms 73512 KB Output is correct
66 Correct 77 ms 58628 KB Output is correct
67 Correct 114 ms 73044 KB Output is correct
68 Correct 14 ms 41308 KB Output is correct
69 Correct 13 ms 33292 KB Output is correct
70 Correct 7 ms 33116 KB Output is correct
71 Correct 10 ms 33116 KB Output is correct