QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#117531#6625. Binariavalerikk#0 12ms17116kbC++171.8kb2023-07-01 15:33:192024-05-31 18:45:43

Judging History

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

  • [2024-05-31 18:45:43]
  • 评测
  • 测评结果:0
  • 用时:12ms
  • 内存:17116kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-01 15:33:19]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
const int N = 105;
#else
const int N = 1e6 + 7;
#endif

const int md = 1e6 + 3;

int mul(int a, int b) {
	return a * 1ll * b % md;
}

int pw(int a, int n) {
	int ret = 1;
	while (n > 0) {
		if (n & 1) {
			ret = mul(ret, a);
		}
		a = mul(a, a);
		n >>= 1;
	}
	return ret;
}

int f[N], rf[N];

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

void upd(int i, int x) {
	if (a[i] != -1 && a[i] != x) {
		cout << "0\n";
		exit(0);
	}
	a[i] = x;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	f[0] = 1;
	for (int i = 1; i < N; ++i) {
		f[i] = mul(f[i - 1], i);
	}
	rf[N - 1] = pw(f[N - 1], md - 2);
	for (int i = N - 2; i >= 0; --i) {
		rf[i] = mul(rf[i + 1], i + 1);
	}
	cin >> n >> k;
	for (int i = 0; i < n - k + 1; ++i) {
		cin >> s[i];
	}
	for (int i = 0; i < n; ++i) {
		a[i] = -1;
	}
	for (int i = 0; i < n - k; ++i) {
		if (abs(s[i] - s[i + 1]) > 1) {
			cout << "0\n";
			return 0;
		}
		if (s[i] + 1 == s[i + 1]) {
			upd(i, 0);
			upd(i + k, 1);
		}
		if (s[i] - 1 == s[i + 1]) {
			upd(i, 1);
			upd(i + k, 0);
		}
	}
	for (int i = 0; i < n - k; ++i) {
		if (s[i] == s[i + 1] && a[i] != -1) {
			if (a[i + k] != -1 && a[i + k] != a[i]) {
				cout << "0\n";
				return 0;
			}
			upd(i + k, a[i]);
		} 
	}
	for (int i = n - k - 1; i >= 0; --i) {
		if (s[i] == s[i + 1] && a[i + k] != -1) {
			if (a[i] != -1 && a[i] != a[i + k]) {
				cout << "0\n";
				return 0;
			}
			upd(i, a[i + k]);
		}
	}
	for (int i = 0; i < n; ++i) {
		if (a[i] != -1) {
			++kek[i % k];
		}
	}
	int cnt = 0;
	for (int i = 0; i < k; ++i) {
		if (kek[i] == 0) {
			++cnt;
		}
	}
	int need = s[0];
	for (int i = 0; i < k; ++i) {
		if (a[i] != -1) {
			need -= a[i];
		}
	}
	if (need < 0 || need > cnt) {
		cout << "0\n";
		return 0;
	}
	cout << mul(f[cnt], mul(rf[need], rf[cnt - need])) << "\n";
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 12ms
memory: 17116kb

input:

1 1
0

output:

0

result:

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

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%