Submission #70063317


Source Code Expand

#include <bits/stdc++.h>
#define int long long
using namespace std;

namespace IO {
	template<typename T> inline void read(T &x) {
		bool f = 1;
		x = 0;
		char ch = getchar();
		while (ch < '0' || ch > '9') {
			if (ch == '-') f = 0;
			ch = getchar();
		}
		while (ch >= '0' && ch <= '9') x = (x << 1) + (x << 3) + (ch & 15), ch = getchar();
		x = f ? x : -x;
	}
	template<typename T> inline void write(T x) {
		if (x < 0) putchar('-'), x = -x;
		if (x > 9) write(x / 10);
		putchar(('0' + x % 10));
	}
	template <typename T, typename ...Args> inline
	void read(T &x, Args &...args) {read(x), read(args...);}
	template<typename T> inline void write(T x, char c) {write(x), putchar(c);}
}
using namespace IO;
using S = vector<pair<int, int>>;

S merge(const S &a, const S &b) {
	unordered_map<int, int> tmp;
	for (auto [s, c] : a) tmp[s] += c;
	for (auto [s, c] : b) tmp[s] += c;
	return S(tmp.begin(), tmp.end());
}

S add(const S &a, int val, int mod) {
	unordered_map<int, int> tmp;
	for (auto [s, c] : a) {
		int sum = (s + val) % mod;
		tmp[sum] += c;
	}
	return S(tmp.begin(), tmp.end());
}

signed main() {
	int n, m;
	read(n, m);
	vector<int> f(n);
	for (int &x : f) read(x);

	if (m == 1) {
		vector<int> dp(n + 1);
		dp[0] = 1;
		if (n >= 1) dp[1] = 2;
		for (int i = 2; i <= n; ++i)
			dp[i] = dp[i - 1] + dp[i - 2];
		write(dp[n], '\n');
		return 0;
	}

	int mid = (n - 1) / 2;

	S ln = {{0, 1}}, ly;
	for (int i = 0; i <= mid; ++i) {
		S nen = merge(ln, ly);
		S ney = add(ln, f[i], m);
		ln.swap(nen);
		ly.swap(ney);
	}

	S rn = {{0, 1}}, ry;
	if (mid + 1 <= n - 1) {
		rn = {{0, 1}};
		ry.clear();
		for (int i = mid + 1; i < n; ++i) {
			S nen = merge(rn, ry);
			S ney = add(rn, f[i], m);
			rn.swap(nen);
			ry.swap(ney);
		}
	}

	unordered_map<int, int> x, y;
	for (auto [s, c] : rn) x[s] = c;
	for (auto [s, c] : ry) y[s] = c;

	int res = 0;
	for (auto [s, c] : ln) {
		int t = (m - s) % m;
		res += c * (x[t] + y[t]);
	}
	for (auto [s, c] : ly) {
		int t = (m - s) % m;
		res += c * x[t];
	}

	write(res, '\n');
	return 0;
}

Submission Info

Submission Time
Task F - Not Adjacent
User NingMeng_yang
Language C++ 20 (gcc 12.2)
Score 0
Code Size 2145 Byte
Status WA
Exec Time 3896 ms
Memory 323540 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 525
Status
AC × 3
AC × 17
WA × 36
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 01_random_40.txt, 01_random_41.txt, 01_random_42.txt, 01_random_43.txt, 01_random_44.txt, 01_random_45.txt, 01_random_46.txt, 01_random_47.txt, 01_random_48.txt, 01_random_49.txt, 01_random_50.txt, 01_random_51.txt, 01_random_52.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3448 KiB
00_sample_01.txt AC 1 ms 3496 KiB
00_sample_02.txt AC 1 ms 3568 KiB
01_random_03.txt WA 3793 ms 323536 KiB
01_random_04.txt WA 3788 ms 323304 KiB
01_random_05.txt WA 3717 ms 323540 KiB
01_random_06.txt WA 3685 ms 323136 KiB
01_random_07.txt WA 3785 ms 323508 KiB
01_random_08.txt WA 3477 ms 316216 KiB
01_random_09.txt WA 3783 ms 323536 KiB
01_random_10.txt WA 3723 ms 323532 KiB
01_random_11.txt AC 1 ms 3520 KiB
01_random_12.txt AC 7 ms 4912 KiB
01_random_13.txt AC 2 ms 3748 KiB
01_random_14.txt WA 100 ms 21496 KiB
01_random_15.txt AC 16 ms 6576 KiB
01_random_16.txt WA 3419 ms 306828 KiB
01_random_17.txt WA 3896 ms 323468 KiB
01_random_18.txt WA 3855 ms 323532 KiB
01_random_19.txt WA 3710 ms 323532 KiB
01_random_20.txt WA 99 ms 17880 KiB
01_random_21.txt WA 3563 ms 317816 KiB
01_random_22.txt WA 3786 ms 323504 KiB
01_random_23.txt WA 2392 ms 227816 KiB
01_random_24.txt AC 2 ms 3752 KiB
01_random_25.txt AC 5 ms 4508 KiB
01_random_26.txt AC 7 ms 4904 KiB
01_random_27.txt AC 1 ms 3628 KiB
01_random_28.txt WA 20 ms 7680 KiB
01_random_29.txt WA 1564 ms 159832 KiB
01_random_30.txt WA 2437 ms 222180 KiB
01_random_31.txt WA 1690 ms 169912 KiB
01_random_32.txt WA 1282 ms 150972 KiB
01_random_33.txt WA 1902 ms 179952 KiB
01_random_34.txt WA 1617 ms 162604 KiB
01_random_35.txt WA 2279 ms 214340 KiB
01_random_36.txt WA 1688 ms 164476 KiB
01_random_37.txt WA 1 ms 3636 KiB
01_random_38.txt AC 1 ms 3572 KiB
01_random_39.txt WA 1 ms 3556 KiB
01_random_40.txt WA 1 ms 3512 KiB
01_random_41.txt WA 34 ms 9684 KiB
01_random_42.txt AC 1 ms 3652 KiB
01_random_43.txt WA 1 ms 3560 KiB
01_random_44.txt WA 1 ms 3584 KiB
01_random_45.txt WA 1 ms 3576 KiB
01_random_46.txt WA 1 ms 3524 KiB
01_random_47.txt WA 1 ms 3568 KiB
01_random_48.txt WA 1 ms 3636 KiB
01_random_49.txt AC 1 ms 3560 KiB
01_random_50.txt AC 1 ms 3476 KiB
01_random_51.txt AC 1 ms 3508 KiB
01_random_52.txt AC 1 ms 3472 KiB