QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#117530#6625. Binariavalerikk#0 8ms17176kbC++171.7kb2023-07-01 15:30:552024-05-31 18:45:42

Judging History

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

  • [2024-05-31 18:45:42]
  • 评测
  • 测评结果:0
  • 用时:8ms
  • 内存:17176kb
  • [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:30:55]
  • 提交

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];

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]) {
			a[i] = 0;
			a[i + k] = 1;
		}
		if (s[i] - 1 == s[i + 1]) {
			a[i] = 1;
			a[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;
			}
			a[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;
			}
			a[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;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 8ms
memory: 17176kb

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%