Submission #70050244


Source Code Expand

#pragma GCC target("prefer-vector-width=512")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using ll = long long;
#define rep(i, s, t) for (ll i = s; i < (ll)(t); i++)
#define all(x) begin(x), end(x)

template <class T> bool chmin(T& x, T y) {
	return x > y ? (x = y, true) : false;
}
template <class T> bool chmax(T& x, T y) {
	return x < y ? (x = y, true) : false;
}

struct io_setup {
	io_setup() {
		ios::sync_with_stdio(false);
		cin.tie(nullptr);
		cout << fixed << setprecision(15);
	}
} io_setup;

int MOD;
pair<map<int, ll>, map<int, ll>> build_MP(vector<ll> v) {
	int n = v.size();
	map<int, ll> res1, res2;
	res2[0] = 1;
	rep(i, 0, n) {
		map<int, ll> nmp;
		for (auto [x, ad] : res2) {
			nmp[(x + v[i]) % MOD] += ad;
			res1[x] += ad;
		}
		swap(res1, nmp);
		swap(res2, nmp);
	}
	return {res1, res2};
}

void solve() {
	int n;
	cin >> n >> MOD;
	vector<ll> a(n);
	rep(i, 0, n) cin >> a[i];
	vector<ll> sa1, sa2;
	rep(i, 0, n / 2) sa1.push_back(a[i]);
	rep(i, n / 2, n) sa2.push_back(a[i]);
	reverse(sa2.begin(), sa2.end());
	auto [bmp1, bmp2] = build_MP(sa1);
	auto [amp1, amp2] = build_MP(sa2);
	ll ans = 0;
	for (auto [ct, ad] : bmp1) {
		auto itr = amp2.find((MOD - ct) % MOD);
		if (itr != amp2.end()) ans += ad * itr->second;
	}
	for (auto [ct, ad] : bmp2) {
		{
			auto itr = amp2.find((MOD - ct) % MOD);
			if (itr != amp2.end()) ans += ad * itr->second;
		}
		{
			auto itr = amp1.find((MOD - ct) % MOD);
			if (itr != amp1.end()) ans += ad * itr->second;
		}
	}
	cout << ans << '\n';
}

int main() {
	int t = 1;
	// cin >> t;
	while (t--) solve();
}

Submission Info

Submission Time
Task F - Not Adjacent
User cho57020
Language C++ 20 (gcc 12.2)
Score 525
Code Size 1741 Byte
Status AC
Exec Time 2747 ms
Memory 411788 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 525 / 525
Status
AC × 3
AC × 53
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 3556 KiB
00_sample_01.txt AC 1 ms 3576 KiB
00_sample_02.txt AC 1 ms 3520 KiB
01_random_03.txt AC 2695 ms 411568 KiB
01_random_04.txt AC 2641 ms 411380 KiB
01_random_05.txt AC 2628 ms 411516 KiB
01_random_06.txt AC 2668 ms 410924 KiB
01_random_07.txt AC 2743 ms 411788 KiB
01_random_08.txt AC 2587 ms 396580 KiB
01_random_09.txt AC 2686 ms 411764 KiB
01_random_10.txt AC 2747 ms 411600 KiB
01_random_11.txt AC 1 ms 3580 KiB
01_random_12.txt AC 9 ms 5612 KiB
01_random_13.txt AC 2 ms 4004 KiB
01_random_14.txt AC 103 ms 26332 KiB
01_random_15.txt AC 18 ms 8340 KiB
01_random_16.txt AC 2335 ms 336228 KiB
01_random_17.txt AC 2707 ms 411388 KiB
01_random_18.txt AC 2702 ms 411632 KiB
01_random_19.txt AC 2703 ms 411676 KiB
01_random_20.txt AC 106 ms 22172 KiB
01_random_21.txt AC 2587 ms 398372 KiB
01_random_22.txt AC 2730 ms 411432 KiB
01_random_23.txt AC 1934 ms 299688 KiB
01_random_24.txt AC 2 ms 3808 KiB
01_random_25.txt AC 5 ms 4844 KiB
01_random_26.txt AC 8 ms 5556 KiB
01_random_27.txt AC 1 ms 3592 KiB
01_random_28.txt AC 22 ms 9080 KiB
01_random_29.txt AC 1359 ms 204400 KiB
01_random_30.txt AC 2009 ms 298916 KiB
01_random_31.txt AC 1484 ms 212232 KiB
01_random_32.txt AC 1071 ms 163244 KiB
01_random_33.txt AC 1694 ms 245116 KiB
01_random_34.txt AC 1416 ms 211240 KiB
01_random_35.txt AC 1906 ms 289048 KiB
01_random_36.txt AC 1484 ms 223856 KiB
01_random_37.txt AC 2 ms 3728 KiB
01_random_38.txt AC 1 ms 3504 KiB
01_random_39.txt AC 1 ms 3632 KiB
01_random_40.txt AC 1 ms 3508 KiB
01_random_41.txt AC 42 ms 13008 KiB
01_random_42.txt AC 1 ms 3516 KiB
01_random_43.txt AC 1 ms 3508 KiB
01_random_44.txt AC 1 ms 3532 KiB
01_random_45.txt AC 1 ms 3720 KiB
01_random_46.txt AC 1 ms 3584 KiB
01_random_47.txt AC 1 ms 3528 KiB
01_random_48.txt AC 1 ms 3572 KiB
01_random_49.txt AC 1 ms 3548 KiB
01_random_50.txt AC 1 ms 3572 KiB
01_random_51.txt AC 1 ms 3632 KiB
01_random_52.txt AC 1 ms 3648 KiB