Submission #1027534

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

using namespace std;

#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 solve() {
    cin>>n>>k;
    for(int i=1; i<=n-k+1; i++) {
        cin>>a[i];
        b[i] = -1;
    }
    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;
        }
    }
    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] || 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 4 ms 29016 KB Output is correct
2 Correct 4 ms 29020 KB Output is correct
3 Correct 5 ms 29020 KB Output is correct
4 Correct 4 ms 29132 KB Output is correct
5 Correct 4 ms 29020 KB Output is correct
6 Incorrect 4 ms 29108 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 29016 KB Output is correct
2 Correct 4 ms 29020 KB Output is correct
3 Correct 5 ms 29020 KB Output is correct
4 Correct 4 ms 29132 KB Output is correct
5 Correct 4 ms 29020 KB Output is correct
6 Incorrect 4 ms 29108 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 29016 KB Output is correct
2 Correct 4 ms 29020 KB Output is correct
3 Correct 5 ms 29020 KB Output is correct
4 Correct 4 ms 29132 KB Output is correct
5 Correct 4 ms 29020 KB Output is correct
6 Incorrect 4 ms 29108 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 29016 KB Output is correct
2 Correct 4 ms 29020 KB Output is correct
3 Correct 5 ms 29020 KB Output is correct
4 Correct 4 ms 29132 KB Output is correct
5 Correct 4 ms 29020 KB Output is correct
6 Incorrect 4 ms 29108 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 29016 KB Output is correct
2 Correct 4 ms 29020 KB Output is correct
3 Correct 5 ms 29020 KB Output is correct
4 Correct 4 ms 29132 KB Output is correct
5 Correct 4 ms 29020 KB Output is correct
6 Incorrect 4 ms 29108 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 29016 KB Output is correct
2 Correct 4 ms 29020 KB Output is correct
3 Correct 5 ms 29020 KB Output is correct
4 Correct 4 ms 29132 KB Output is correct
5 Correct 4 ms 29020 KB Output is correct
6 Incorrect 4 ms 29108 KB Output isn't correct
7 Halted 0 ms 0 KB -