QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#334247#6625. Binariajames1BadCreeper0 1ms3712kbC++141.6kb2024-02-21 15:58:012024-02-21 15:58:02

Judging History

你现在查看的是最新测评结果

  • [2024-02-21 15:58:02]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:3712kb
  • [2024-02-21 15:58:01]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std; 
const int P = 1e6 + 3; 
const int N = 1e6 + 5; 

inline int poww(int a, int b) {
    int r = 1; 
    for (; b; b >>= 1, a = 1ll * a * a % P) if (b & 1) r = 1ll * r * a % P; 
    return r; 
}

int n, k; 
int s[N], fa[N]; 
int a[N]; 

int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }

int C(int n, int m) {
    if (n < m || m < 0) return 0; 
    int ans = 1;
    for (int i = 1; i <= m; ++i) ans = 1ll * ans * (n - i + 1) % P * poww(i, P - 2) % P;  
    return ans; 
}

int main(void) {
    ios::sync_with_stdio(0); 
    cin >> n >> k; 
    for (int i = k; i <= n; ++i) cin >> s[i]; 
    for (int i = 1; i <= n; ++i) fa[i] = i, a[i] = -1; 
    for (int i = k + 1; i <= n; ++i) {
        int y = find(i), x = find(i - k); 
        if (s[i] == s[i - 1]) {
            if (x == y) continue; 
            if (a[x] != -1) fa[y] = x; 
            else fa[x] = y; 
        } else if (s[i] == s[i - 1] - 1) {
            if (x == y) return cout << "0\n", 0; 
            if (a[x] == 0 || a[y] == 1) return cout << "0\n", 0; 
            a[x] = 1, a[y] = 0; 
        } else if (s[i] - 1 == s[i - 1]) {
            if (x == y) return cout << "0\n", 0; 
            if (a[x] == 1 || a[y] == 0) return cout << "0\n", 0; 
            a[x] = 0, a[y] = 1; 
        } else return cout << "0\n", 0; 
    }
    int t = 0, all = k; 
    for (int i = 1; i <= k; ++i) t += (a[i] == 1), all -= (a[i] != -1); 
    t = s[k] - t; 
    // cout << all << ' ' << t << '\n'; 
    cout << C(all, t) << '\n'; 
    return 0; 
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 3
Accepted
time: 1ms
memory: 3600kb

input:

1 1
0

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3644kb

input:

1 1
1

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3628kb

input:

10 3
1 2 2 2 2 2 2 2

output:

2

result:

ok 1 number(s): "2"

Test #4:

score: 0
Accepted
time: 1ms
memory: 3712kb

input:

10 3
1 1 0 1 2 3 2 2

output:

1

result:

ok 1 number(s): "1"

Test #5:

score: 0
Accepted
time: 1ms
memory: 3596kb

input:

10 3
2 2 2 2 2 2 2 2

output:

3

result:

ok 1 number(s): "3"

Test #6:

score: -3
Wrong Answer
time: 1ms
memory: 3592kb

input:

10 3
2 1 1 1 1 2 2 3

output:

2

result:

wrong answer 1st numbers differ - expected: '1', found: '2'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Skipped

Dependency #5:

0%