답안 #851552

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
851552 2023-09-20T06:32:06 Z khanhphucscratch Binaria (CCO23_day1problem1) C++14
0 / 25
1 ms 6608 KB
#include<bits/stdc++.h>
#define int long long
using namespace std;
int a[1000001], fact[1000001], inv[1000001], color[1000001];
const int mod = 1e6+3;
int power(int a, int b)
{
    if(b == 0) return 1;
    int ans = power(a, b/2);
    ans = (ans * ans)%mod;
    if(b%2 == 1) ans = (ans * a)%mod;
    return ans;
}
int C(int k, int n)
{
    if(k > n || k < 0) return 0;
    return (fact[n] * ((inv[k] * inv[n-k])%mod))%mod;
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin>>n>>k;
    fact[0] = inv[0] = 1;
    for(int i = 1; i <= n; i++) fact[i] = (fact[i-1] * i)%mod;
    inv[n] = power(fact[n], mod-2);
    for(int i = n-1; i >= 1; i--) inv[i] = (inv[i+1] * (i+1))%mod;
    for(int i = 1; i <= n-k+1; i++) cin>>a[i];
    for(int i = 1; i <= n; i++) color[i] = 2;
    for(int i = n-k; i >= 1; i--){
        if(abs(a[i] - a[i+1]) > 1){cout<<0; return 0;}
        if(a[i] == a[i+1]) color[i] = color[i+k];
        else if(a[i] > a[i+1]){
            if(color[i+k] == 1){cout<<0; return 0;}
            color[i] = 1;
        }
        else{
            if(color[i+k] == 0){cout<<0; return 0;}
            color[i] = 0;
        }
    }
    for(int i = 1; i <= k; i++){a[i] -= (color[i] == 1); k -= (color[i] < 2);}
    cout<<C(a[1], k);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6608 KB Output is correct
2 Correct 1 ms 6488 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6488 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6488 KB Output is correct
7 Incorrect 1 ms 6488 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6608 KB Output is correct
2 Correct 1 ms 6488 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6488 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6488 KB Output is correct
7 Incorrect 1 ms 6488 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6608 KB Output is correct
2 Correct 1 ms 6488 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6488 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6488 KB Output is correct
7 Incorrect 1 ms 6488 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6608 KB Output is correct
2 Correct 1 ms 6488 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6488 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6488 KB Output is correct
7 Incorrect 1 ms 6488 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6608 KB Output is correct
2 Correct 1 ms 6488 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6488 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6488 KB Output is correct
7 Incorrect 1 ms 6488 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6608 KB Output is correct
2 Correct 1 ms 6488 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6488 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6488 KB Output is correct
7 Incorrect 1 ms 6488 KB Output isn't correct
8 Halted 0 ms 0 KB -