Submission #1037073

# Submission time Handle Problem Language Result Execution time Memory
1037073 2024-07-28T02:46:01 Z fryingduc Binaria (CCO23_day1problem1) C++17
0 / 25
116 ms 12936 KB
#include "bits/stdc++.h"
using namespace std;

const int maxn = 1e6 + 6;
const int mod = 1e6 + 3;
int n, k;
int a[maxn], force[maxn];
bool check[maxn];
int fact[maxn], inv[maxn];

int power(int a, int b) {
    if(b == 0) return 1;
    int ans = power(a, b / 2);
    ans = (1ll * ans * ans % mod);
    if(b & 1) return 1ll * ans * a % mod;
    return ans;
}
int C(int n, int k) {
    if(k > n) return 0;
    return 1ll * fact[n] * inv[n - k] % mod * inv[k] % mod;
}
void solve() {
    cin >> n >> k;
    for(int i = 1; i <= n - k + 1; ++i) {
        cin >> a[i];
    }
    fill(force, force + n + 1, -1);
    for(int i = 2, j = k + 1; i <= n - k + 1; ++i, ++j) {
        if(a[i] > a[i - 1]) {
            force[j] = 1, force[j - k] = 0;
        }
        else if(a[i] < a[i - 1]) {
            force[j - k] = 1, force[j] = 0;
        }
    }
    int cnt = 0;
    for(int i = 1; i <= k; ++i) {
        if(force[i] == -1) ++cnt;
        else {
            a[1] -= force[i];
        }
    }
    cout << C(cnt, a[1]);
}
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    fact[0] = inv[0] = 1;
    for(int i = 1; i < maxn; ++i) {
        fact[i] = 1ll * fact[i - 1] * i % mod;
        inv[i] = power(fact[i], mod - 2);
    }
    
    solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 114 ms 12932 KB Output is correct
2 Correct 116 ms 12936 KB Output is correct
3 Correct 114 ms 12884 KB Output is correct
4 Correct 114 ms 12924 KB Output is correct
5 Correct 113 ms 12888 KB Output is correct
6 Incorrect 113 ms 12884 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 114 ms 12932 KB Output is correct
2 Correct 116 ms 12936 KB Output is correct
3 Correct 114 ms 12884 KB Output is correct
4 Correct 114 ms 12924 KB Output is correct
5 Correct 113 ms 12888 KB Output is correct
6 Incorrect 113 ms 12884 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 114 ms 12932 KB Output is correct
2 Correct 116 ms 12936 KB Output is correct
3 Correct 114 ms 12884 KB Output is correct
4 Correct 114 ms 12924 KB Output is correct
5 Correct 113 ms 12888 KB Output is correct
6 Incorrect 113 ms 12884 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 114 ms 12932 KB Output is correct
2 Correct 116 ms 12936 KB Output is correct
3 Correct 114 ms 12884 KB Output is correct
4 Correct 114 ms 12924 KB Output is correct
5 Correct 113 ms 12888 KB Output is correct
6 Incorrect 113 ms 12884 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 114 ms 12932 KB Output is correct
2 Correct 116 ms 12936 KB Output is correct
3 Correct 114 ms 12884 KB Output is correct
4 Correct 114 ms 12924 KB Output is correct
5 Correct 113 ms 12888 KB Output is correct
6 Incorrect 113 ms 12884 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 114 ms 12932 KB Output is correct
2 Correct 116 ms 12936 KB Output is correct
3 Correct 114 ms 12884 KB Output is correct
4 Correct 114 ms 12924 KB Output is correct
5 Correct 113 ms 12888 KB Output is correct
6 Incorrect 113 ms 12884 KB Output isn't correct
7 Halted 0 ms 0 KB -