QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#200904 | #6355. 5 | ucup-team859 | WA | 0ms | 3588kb | C++14 | 2.1kb | 2023-10-04 23:33:07 | 2023-10-04 23:33:07 |
Judging History
answer
#include <bits/stdc++.h>
#include <iterator>
#define lsb(x) (x & (-x))
using ull = unsigned long long;
using ll = long long;
using namespace std;
inline bool intersect(pair<int, int> &x, pair<int, int> &y) {
return !(x.second < y.first || y.second < x.first || (x.first <= y.first && y.second <= x.second));
}
inline void merge(vector<pair<int, int>> &x, vector<pair<int, int>> &y, int add = 1) {
for (auto interval : y) {
auto to_merge = make_pair(interval.first + add, interval.second + add);
for (auto it = x.begin(); !x.empty() && it != x.end();) {
if (intersect(*it, to_merge)) {
to_merge.first = min(to_merge.first, it->first);
to_merge.second = max(to_merge.second, it->second);
auto tmp = next(it);
x.erase(it);
it = tmp;
} else {
it = next(it);
}
}
x.push_back(to_merge);
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, s;
cin >> n >> s;
vector<int> cnt(s + 1, 0);
vector<int> a(n + 1, 0);
int cnt_neg = 0, new_s = 0;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
a[i] -= 1;
if (a[i] >= 0) {
++cnt[a[i]];
new_s += a[i];
}
else
++cnt_neg;
}
s = new_s;
vector<vector<pair<int, int>>> dp(s + 1);
int sx = 0;
for (int val = 0; val <= s; ++val) {
if (!cnt[val])
continue;
if (val == 0) {
dp[0].push_back({0, cnt[val]});
continue;
}
sx += val * cnt[val];
for (int j = sx; j >= val; --j) {
for (int x = val, nr = 1; x <= j && nr <= cnt[val]; x += val, ++nr)
merge(dp[j], dp[j - x], nr);
}
}
ll ans = 0;
for (int i = 1; i <= cnt_neg; ++i) {
for (auto interval : dp[0])
ans += interval.second - interval.first + 1;
for (int j = 0; j < s; ++j) {
if (!dp[j + 1].empty())
merge(dp[j], dp[j + 1]);
}
}
for (auto it : dp)
for (auto interval : it)
ans += interval.second - interval.first + 1;
cout << ans << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3588kb
input:
7 9 0 0 0 1 1 2 5
output:
65
result:
wrong answer 1st numbers differ - expected: '42', found: '65'