이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//ᗜˬᗜ
#include<bits/stdc++.h>
#define int long long
#define vi vector <int>
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define pb emplace_back
#define fu(i, a, b) for(int i = (a); i < (b); i++)
#define fub(i, a, b) for(int i = (a); i <= (b); i++)
#define pii pair<int, int>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
const int lim = 1e18;
const int N = 1e6 + 3;
const int M = 1e9 + 7;
int n, k, res;
int a[N], mp[N];
int expo(int a, int b){
    if(b == 0)return 1;
    if(b%2 == 0)return expo((a*a)%N, b/2)%N;
    return (a*expo((a*a)%N, b/2))%N;
}
int bico(int n, int k){
    if(k > n or n < 0 or k < 0)return 0;
    int res = 1;
    fub(i, k+1, n)res = (res*i)%N;
    fub(i, 1, n-k)res = (res*expo(i, N-2))%N;
    return res;
}
signed main(){
    fastio;
    cin >> n >> k;
    fub(i, 1, n-k+1)cin >> a[i];
    memset(mp, -1, sizeof(mp));
    fub(i, 2, n-k+1){
        if(abs(a[i] - a[i-1]) > 1){
            cout << 0;
            return 0;
        }
    }
    fub(i, 2, n-k+1){
        if(a[i] - a[i-1] == 1){
            mp[i+k-1] = 1; mp[i-1] = 0;
        }
        else if(a[i] - a[i-1] == -1){
            mp[i+k-1] = 0; mp[i-1] = 1;
        }
        else mp[i+k-1] = mp[i-1];
    }
    for(int i = n-k; i >= 1; i--)if(a[i] == a[i+1])mp[i] = mp[i+k];
    fub(i, 1, k){
        res += (mp[i] == -1);
        a[1] -= (mp[i] == 1);
    }
    cout << bico(res, a[1]);
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |