# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
932849 | Son | Binaria (CCO23_day1problem1) | C++14 | 304 ms | 21052 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define pb push_back
#define fi first
#define se second
#define mp make_pair
int n,k;
int A[1000005];
int fact[1000005], inv[1000005];
int mo = 1e6 + 3;
int B[1000005];
int expo( int a, int b ){
if ( b == 0 ) return 1;
int half = expo(a,b/2);
half = ( 1LL * half * half ) % mo;
if ( b & 1 ){
half = ( 1LL * half * a ) % mo;
}
return half;
}
int C( int N, int K ){
if ( K > N || K < 0 ) return 0;
int ans = (fact[N] * 1LL * inv[K]) % mo;
ans = ( ans * 1LL * inv[N-K] ) % mo;
return ans;
}
void fail(){
printf("0\n");
exit(0);
}
int main(){
scanf("%d%d",&n,&k);
for ( int i = 1; i <= n-k+1; i++ ){
scanf("%d",&A[i]);
}
fact[0] = inv[0] = 1;
for ( int i = 1; i <= n; i++ ){
fact[i] = ( fact[i-1] * 1LL * i ) % mo;
inv[i] = expo(fact[i], mo - 2) % mo;
B[i] = 2;
}
for ( int i = n-k; i >= 1; i-- ){
if ( abs(A[i] - A[i+1]) > 1 ){
fail();
}
if ( A[i] > A[i+1] ){
if ( B[i+k] == 1 ){
fail();
}
B[i] = 1;
} else if ( A[i] < A[i+1] ){
if ( B[i+k] == 0 ){
fail();
}
B[i] = 0;
} else {
B[i] = B[i+k];
}
}
int N = 0, K = A[1];
for ( int i = 1; i <= k; i++ ){
if ( B[i] == 1 ){
K--;
}
if ( B[i] == 2 ){
N++;
}
}
printf("%d\n",C(N,K));
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |