제출 #1027280

#제출 시각아이디문제언어결과실행 시간메모리
1027280khanhtbBinaria (CCO23_day1problem1)C++14
25 / 25
69 ms31648 KiB
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define pf push_front
#define vi vector<ll>
#define vii vector<vi>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define all(a) a.begin(), a.end()
#define fi first
#define se second
using namespace std;
const ll mod = 1e6 + 3;
const ll inf = 2e18;
const ll blocksz = 320;
const ll N = 1e6 + 1;
ll n,fac[N],invfac[N];
ll bipow(ll a, ll b){
    ll ans = 1;
    while(b){
        if(b&1) ans = ans*a%mod;
        a = a*a%mod;
        b>>=1;
    }
    return ans;
}
void precalc(){
    fac[0] = 1;
    for(ll i = 1; i < N; i++) fac[i] = fac[i-1]*i%mod;
    invfac[N-1] = bipow(fac[N-1],mod-2);
    for(ll i = N-2; i >= 0; i--) invfac[i] = invfac[i+1]*(i+1)%mod;
}
ll C(ll k, ll n){
    if(k > n || k < 0) return 0;
    return ((fac[n]*invfac[k])%mod)*invfac[n-k]%mod;
}
ll k,a[N];
ll d[N];
void solve(){
    cin >> n >> k;
    fill(a,a+n+1,-1);
    for(ll i = 1; i <= n-k+1; i++) cin >> d[i];
    for(ll i = n-k; i >= 1; i--){
        if(abs(d[i]-d[i+1]) > 1){
            cout << 0;
            return;
        }
        if(d[i] > d[i+1]){
            if(a[i+k] == 1){
                cout << 0;
                return;
            }
            a[i] = 1;
        }
        else if(d[i] < d[i+1]){
            if(a[i+k] == 0){
                cout << 0;
                return;
            }
            a[i] = 0;
        }
        else if(d[i] == d[i+1]) a[i] = a[i+k];
    }
    precalc();
    ll cnt = 0;
    ll n1 = d[1];
    for(ll i = 1; i <= k; i++){
        if(a[i] == -1) cnt++;
        if(a[i] == 1) n1--;
    }
    cout << C(n1,cnt);
}
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if (fopen("test.inp", "r")){
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }
    ll T = 1;
    // cin >> T;
    for (ll i = 1; i <= T; i++){
        solve();
        cout << '\n';
    }
}

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'int main()':
Main.cpp:80:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   80 |         freopen("test.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:81:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   81 |         freopen("test.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...