Submission #3655258


Source Code Expand

Copy
#include <bits/stdc++.h>

#ifdef NON_SUBMIT
#define TEST(n) (n)
#else
#define TEST(n) ((void)0)
#endif

using namespace std;

vector<long long> S, NS;
long long PS[1001];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt", "r", stdin));
	TEST(freopen("output.txt", "w", stdout));
	TEST(freopen("debug.txt", "w", stderr));
	int N, K;
	long long f, ans = 0;
	cin >> N >> K;
	for (int i = 1; i <= N; i++) {
		cin >> PS[i];
		PS[i] += PS[i - 1];
		for (int j = 0; j < i; j++) S.push_back(PS[i] - PS[j]);
	}
	sort(S.begin(), S.end(), greater<long long>());
	for (f = 1; f <= S[0]; f <<= 1);
	for (f >>= 1; f; f >>= 1) {
		NS.clear();
		for (auto s : S) {
			if (s&f) NS.push_back(s);
		}
		if (NS.size() >= K) ans |= f, S = NS;
	}
	cout << ans << '\n';
	return 0;
}

Submission Info

Submission Time
Task B - Sum AND Subarrays
User Lawali
Language C++14 (GCC 5.4.1)
Score 400
Code Size 850 Byte
Status
Exec Time 39 ms
Memory 6384 KB

Test Cases

Set Name Score / Max Score Test Cases
All 400 / 400 n-large-k-small1, n-large-k-small2, n-large-k-small3, n-large-k-small4, n-large-k-small5, n-medium-1, n-medium-2, n-medium-3, n-medium-4, n-medium-5, n-medium-6, n-medium-7, n-medium-k-small-1, n-medium-k-small-2, n-small-1, n-small-2, n-small-3, nk-large-1, nk-large-2, sample_01, sample_02
Case Name Status Exec Time Memory
n-large-k-small1 34 ms 5996 KB
n-large-k-small2 34 ms 5996 KB
n-large-k-small3 34 ms 6000 KB
n-large-k-small4 34 ms 6384 KB
n-large-k-small5 34 ms 5996 KB
n-medium-1 16 ms 2420 KB
n-medium-2 26 ms 4720 KB
n-medium-3 2 ms 512 KB
n-medium-4 3 ms 892 KB
n-medium-5 2 ms 512 KB
n-medium-6 30 ms 5872 KB
n-medium-7 17 ms 2544 KB
n-medium-k-small-1 2 ms 512 KB
n-medium-k-small-2 8 ms 1524 KB
n-small-1 1 ms 256 KB
n-small-2 1 ms 384 KB
n-small-3 1 ms 256 KB
nk-large-1 39 ms 5996 KB
nk-large-2 35 ms 6384 KB
sample_01 1 ms 256 KB
sample_02 1 ms 256 KB