Submission #967954

# Submission time Handle Problem Language Result Execution time Memory
967954 2024-04-23T06:03:32 Z Darren0724 Binaria (CCO23_day1problem1) C++17
10 / 25
1000 ms 79772 KB
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define ll long long 
#define LCBorz ios_base::sync_with_stdio(false);cin.tie(0);
const int N=1000005;
const int mod=1e6+3;
vector<ll> fac(N),inv(N);
ll pw(ll a,int b){
    ll ans=1;
    while(b>0){
        if(b&1)ans=ans*a%mod;
        b>>=1;
        a=a*a%mod;
    }
    return ans;
}
int32_t main(){
    LCBorz;
    fac[0]=inv[0]=1;
    for(int i=1;i<N;i++){
        fac[i]=fac[i-1]*i%mod;
        inv[i]=pw(fac[i],mod-2);
    }
    int n,m;cin>>n>>m;
    int p=n-m+1;
    vector<int> v(p);
    for(int i=0;i<p;i++){
        cin>>v[i];
        if(v[i]>m){
            cout<<0<<endl;
            return 0;
        }
    }
    vector<int> ans(n,-1);
    auto upd=[&](int i,int j){
        if(ans[i]==-1){
            ans[i]=j;
        }
        else if(ans[i]!=j){
            cout<<0<<endl;
            exit(0);
        }
    };
    vector<int> adj[N];
    auto dfs=[&](auto dfs1,int k,int pa,int val)->void {
        upd(k,val);
        for(int j:adj[k]){
            if(j==pa)continue;
            dfs1(dfs1,j,k,val);
        }
    }; 
    for(int i=0;i<p-1;i++){
        if(abs(v[i]-v[i+1])>1){
            cout<<0<<endl;
            return 0;
        }
        if(v[i]==v[i+1]+1){
            upd(i,1);
            upd(i+m,0);
        }
        else if(v[i]==v[i+1]-1){
            upd(i,0);
            upd(i+m,1);
        }
        else{
            adj[i].push_back(i+m);
            adj[i+m].push_back(i);
        }
    }
    for(int i=0;i<n;i++){
        if(ans[i]!=-1){
            dfs(dfs,i,i,ans[i]);
        }
    }
    int a=0,b=v[0];
    for(int i=0;i<m;i++){
        if(ans[i]==-1){
            a++;
        }
        if(ans[i]==1){
            b--;
        }
    }
    if(b>a||b<0){
        cout<<0<<endl;
        return 0;
    }
    cout<<fac[a]*inv[b]%mod*inv[a-b]%mod<<endl;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 115 ms 39768 KB Output is correct
2 Correct 107 ms 39584 KB Output is correct
3 Correct 107 ms 39580 KB Output is correct
4 Correct 105 ms 39840 KB Output is correct
5 Correct 107 ms 39588 KB Output is correct
6 Correct 110 ms 39584 KB Output is correct
7 Correct 107 ms 39580 KB Output is correct
8 Correct 112 ms 39516 KB Output is correct
9 Correct 109 ms 39584 KB Output is correct
10 Correct 107 ms 39588 KB Output is correct
11 Correct 109 ms 39576 KB Output is correct
12 Correct 108 ms 39588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 115 ms 39768 KB Output is correct
2 Correct 107 ms 39584 KB Output is correct
3 Correct 107 ms 39580 KB Output is correct
4 Correct 105 ms 39840 KB Output is correct
5 Correct 107 ms 39588 KB Output is correct
6 Correct 110 ms 39584 KB Output is correct
7 Correct 107 ms 39580 KB Output is correct
8 Correct 112 ms 39516 KB Output is correct
9 Correct 109 ms 39584 KB Output is correct
10 Correct 107 ms 39588 KB Output is correct
11 Correct 109 ms 39576 KB Output is correct
12 Correct 108 ms 39588 KB Output is correct
13 Correct 108 ms 39528 KB Output is correct
14 Correct 107 ms 39516 KB Output is correct
15 Correct 106 ms 39576 KB Output is correct
16 Correct 109 ms 39576 KB Output is correct
17 Correct 107 ms 39516 KB Output is correct
18 Correct 107 ms 39572 KB Output is correct
19 Correct 109 ms 39588 KB Output is correct
20 Correct 110 ms 39588 KB Output is correct
21 Correct 108 ms 39372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 115 ms 39768 KB Output is correct
2 Correct 107 ms 39584 KB Output is correct
3 Correct 107 ms 39580 KB Output is correct
4 Correct 105 ms 39840 KB Output is correct
5 Correct 107 ms 39588 KB Output is correct
6 Correct 110 ms 39584 KB Output is correct
7 Correct 107 ms 39580 KB Output is correct
8 Correct 112 ms 39516 KB Output is correct
9 Correct 109 ms 39584 KB Output is correct
10 Correct 107 ms 39588 KB Output is correct
11 Correct 109 ms 39576 KB Output is correct
12 Correct 108 ms 39588 KB Output is correct
13 Correct 108 ms 39528 KB Output is correct
14 Correct 107 ms 39516 KB Output is correct
15 Correct 106 ms 39576 KB Output is correct
16 Correct 109 ms 39576 KB Output is correct
17 Correct 107 ms 39516 KB Output is correct
18 Correct 107 ms 39572 KB Output is correct
19 Correct 109 ms 39588 KB Output is correct
20 Correct 110 ms 39588 KB Output is correct
21 Correct 108 ms 39372 KB Output is correct
22 Correct 106 ms 39596 KB Output is correct
23 Correct 112 ms 39592 KB Output is correct
24 Correct 107 ms 39596 KB Output is correct
25 Correct 110 ms 39528 KB Output is correct
26 Correct 109 ms 39644 KB Output is correct
27 Correct 106 ms 39596 KB Output is correct
28 Correct 108 ms 39604 KB Output is correct
29 Correct 110 ms 39612 KB Output is correct
30 Correct 106 ms 39516 KB Output is correct
31 Correct 107 ms 39512 KB Output is correct
32 Correct 108 ms 39584 KB Output is correct
33 Correct 107 ms 39600 KB Output is correct
34 Correct 110 ms 39516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 115 ms 39768 KB Output is correct
2 Correct 107 ms 39584 KB Output is correct
3 Correct 107 ms 39580 KB Output is correct
4 Correct 105 ms 39840 KB Output is correct
5 Correct 107 ms 39588 KB Output is correct
6 Correct 110 ms 39584 KB Output is correct
7 Correct 107 ms 39580 KB Output is correct
8 Correct 112 ms 39516 KB Output is correct
9 Correct 109 ms 39584 KB Output is correct
10 Correct 107 ms 39588 KB Output is correct
11 Correct 109 ms 39576 KB Output is correct
12 Correct 108 ms 39588 KB Output is correct
13 Correct 108 ms 39528 KB Output is correct
14 Correct 107 ms 39516 KB Output is correct
15 Correct 106 ms 39576 KB Output is correct
16 Correct 109 ms 39576 KB Output is correct
17 Correct 107 ms 39516 KB Output is correct
18 Correct 107 ms 39572 KB Output is correct
19 Correct 109 ms 39588 KB Output is correct
20 Correct 110 ms 39588 KB Output is correct
21 Correct 108 ms 39372 KB Output is correct
22 Correct 106 ms 39596 KB Output is correct
23 Correct 112 ms 39592 KB Output is correct
24 Correct 107 ms 39596 KB Output is correct
25 Correct 110 ms 39528 KB Output is correct
26 Correct 109 ms 39644 KB Output is correct
27 Correct 106 ms 39596 KB Output is correct
28 Correct 108 ms 39604 KB Output is correct
29 Correct 110 ms 39612 KB Output is correct
30 Correct 106 ms 39516 KB Output is correct
31 Correct 107 ms 39512 KB Output is correct
32 Correct 108 ms 39584 KB Output is correct
33 Correct 107 ms 39600 KB Output is correct
34 Correct 110 ms 39516 KB Output is correct
35 Correct 216 ms 79772 KB Output is correct
36 Execution timed out 1086 ms 79188 KB Time limit exceeded
37 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 115 ms 39768 KB Output is correct
2 Correct 107 ms 39584 KB Output is correct
3 Correct 107 ms 39580 KB Output is correct
4 Correct 105 ms 39840 KB Output is correct
5 Correct 107 ms 39588 KB Output is correct
6 Correct 110 ms 39584 KB Output is correct
7 Correct 107 ms 39580 KB Output is correct
8 Correct 112 ms 39516 KB Output is correct
9 Correct 109 ms 39584 KB Output is correct
10 Correct 107 ms 39588 KB Output is correct
11 Correct 109 ms 39576 KB Output is correct
12 Correct 108 ms 39588 KB Output is correct
13 Correct 108 ms 39528 KB Output is correct
14 Correct 107 ms 39516 KB Output is correct
15 Correct 106 ms 39576 KB Output is correct
16 Correct 109 ms 39576 KB Output is correct
17 Correct 107 ms 39516 KB Output is correct
18 Correct 107 ms 39572 KB Output is correct
19 Correct 109 ms 39588 KB Output is correct
20 Correct 110 ms 39588 KB Output is correct
21 Correct 108 ms 39372 KB Output is correct
22 Correct 106 ms 39596 KB Output is correct
23 Correct 112 ms 39592 KB Output is correct
24 Correct 107 ms 39596 KB Output is correct
25 Correct 110 ms 39528 KB Output is correct
26 Correct 109 ms 39644 KB Output is correct
27 Correct 106 ms 39596 KB Output is correct
28 Correct 108 ms 39604 KB Output is correct
29 Correct 110 ms 39612 KB Output is correct
30 Correct 106 ms 39516 KB Output is correct
31 Correct 107 ms 39512 KB Output is correct
32 Correct 108 ms 39584 KB Output is correct
33 Correct 107 ms 39600 KB Output is correct
34 Correct 110 ms 39516 KB Output is correct
35 Correct 216 ms 79772 KB Output is correct
36 Execution timed out 1086 ms 79188 KB Time limit exceeded
37 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 115 ms 39768 KB Output is correct
2 Correct 107 ms 39584 KB Output is correct
3 Correct 107 ms 39580 KB Output is correct
4 Correct 105 ms 39840 KB Output is correct
5 Correct 107 ms 39588 KB Output is correct
6 Correct 110 ms 39584 KB Output is correct
7 Correct 107 ms 39580 KB Output is correct
8 Correct 112 ms 39516 KB Output is correct
9 Correct 109 ms 39584 KB Output is correct
10 Correct 107 ms 39588 KB Output is correct
11 Correct 109 ms 39576 KB Output is correct
12 Correct 108 ms 39588 KB Output is correct
13 Correct 108 ms 39528 KB Output is correct
14 Correct 107 ms 39516 KB Output is correct
15 Correct 106 ms 39576 KB Output is correct
16 Correct 109 ms 39576 KB Output is correct
17 Correct 107 ms 39516 KB Output is correct
18 Correct 107 ms 39572 KB Output is correct
19 Correct 109 ms 39588 KB Output is correct
20 Correct 110 ms 39588 KB Output is correct
21 Correct 108 ms 39372 KB Output is correct
22 Correct 106 ms 39596 KB Output is correct
23 Correct 112 ms 39592 KB Output is correct
24 Correct 107 ms 39596 KB Output is correct
25 Correct 110 ms 39528 KB Output is correct
26 Correct 109 ms 39644 KB Output is correct
27 Correct 106 ms 39596 KB Output is correct
28 Correct 108 ms 39604 KB Output is correct
29 Correct 110 ms 39612 KB Output is correct
30 Correct 106 ms 39516 KB Output is correct
31 Correct 107 ms 39512 KB Output is correct
32 Correct 108 ms 39584 KB Output is correct
33 Correct 107 ms 39600 KB Output is correct
34 Correct 110 ms 39516 KB Output is correct
35 Correct 216 ms 79772 KB Output is correct
36 Execution timed out 1086 ms 79188 KB Time limit exceeded
37 Halted 0 ms 0 KB -