Contest Duration: ~ (local time) (120 minutes)

Submission #3658430

Source Code Expand

Copy
```#include <iostream>
#include <vector>
#include <utility>
#include <numeric>
#include <functional>
#include <stdio.h>
#include <math.h>
#include <string>
#include <algorithm>
#include <deque>
#include <queue>
#include <map>
#include <chrono>
using namespace std;
using ll = long long;

ll maxd(vector<ll> &v, ll maxa, ll k) {
ll a = 1;
while(maxa >= a) {
a <<= 1;
}
a >>= 1;
while (a > 0) {
a >>= 1;
ll count = 0;
for (auto i : v) {
if ((i & a) >= a) {
++count;
if (count == k) {
return a;
}
}
}
}
return a;
}

vector<ll> cut(vector<ll> &v, ll a) {
vector<ll> vv(0);
for (auto i : v) {
if ((i & a) >= a) {
vv.push_back(i);
}
}
return vv;
}

int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
ll N, K;
cin >> N >> K;
ll s[1002][1002];
for (ll i = 0; i != N; ++i) {
for (ll j = 0; j <= N; ++j) {
s[i][j] = 0;
}
}
vector<ll> vs;
for (ll i = 0; i != N; ++i) {
ll a;
cin >> a;
for (ll j = 0; j <= i; ++j) {
s[i + 1][j] = s[i][j] + a;
vs.push_back(s[i + 1][j]);
}
}
ll out = 0;
ll a = 1e14;
while (a > 0) {
a = maxd(vs, a, K);
out += a;
vs = cut(vs, a);
// for (auto i : vs) {
// 	cout << i << endl;
// }
// cout << endl;
}
cout << out << endl;
}
```

#### Submission Info

Submission Time 2018-11-24 21:40:07+0900 B - Sum AND Subarrays taku0728 C++14 (GCC 5.4.1) 400 1337 Byte AC 16 ms 14320 KB

#### Judge Result

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 11 ms 13932 KB
n-large-k-small2 11 ms 13804 KB
n-large-k-small3 11 ms 13808 KB
n-large-k-small4 11 ms 13932 KB
n-large-k-small5 11 ms 14320 KB
n-medium-1 6 ms 8052 KB
n-medium-2 9 ms 12272 KB
n-medium-3 2 ms 1152 KB
n-medium-4 3 ms 4220 KB
n-medium-5 2 ms 1408 KB
n-medium-6 10 ms 13168 KB
n-medium-7 7 ms 9456 KB
n-medium-k-small-1 2 ms 3072 KB
n-medium-k-small-2 4 ms 4984 KB
n-small-1 1 ms 384 KB
n-small-2 2 ms 768 KB
n-small-3 1 ms 384 KB
nk-large-1 16 ms 13804 KB
nk-large-2 12 ms 13804 KB
sample_01 1 ms 256 KB
sample_02 1 ms 256 KB