QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#200900 | #6355. 5 | ucup-team859 | TL | 568ms | 3932kb | C++14 | 2.0kb | 2023-10-04 23:28:52 | 2023-10-04 23:28:52 |
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);
}
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);
for (int val = 0; val <= s; ++val) {
if (!cnt[val])
continue;
if (val == 0) {
dp[0].push_back({0, cnt[val]});
continue;
}
for (int j = s; j >= val; --j) {
for (int x = val, nr = 1; x <= j && nr <= cnt[val]; x += val, ++nr)
merge(dp[j], dp[j - x], nr);
}
}
if (n >= 100000)
return 0;
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;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3536kb
input:
7 9 0 0 0 1 1 2 5
output:
42
result:
ok 1 number(s): "42"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3472kb
input:
10 33 9 9 8 1 1 1 1 1 1 1
output:
48
result:
ok 1 number(s): "48"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3480kb
input:
10 14 2 4 4 1 0 1 0 1 0 1
output:
81
result:
ok 1 number(s): "81"
Test #4:
score: 0
Accepted
time: 1ms
memory: 3480kb
input:
10 14 3 5 3 0 1 0 1 0 1 0
output:
87
result:
ok 1 number(s): "87"
Test #5:
score: 0
Accepted
time: 1ms
memory: 3432kb
input:
40 50 1 1 1 1 3 3 0 3 1 1 0 0 2 1 0 0 1 0 0 2 7 1 2 1 3 0 2 2 3 1 1 0 0 2 0 1 1 0 1 1
output:
1067
result:
ok 1 number(s): "1067"
Test #6:
score: 0
Accepted
time: 1ms
memory: 3512kb
input:
1200 1000 1 1 2 3 0 1 0 0 1 1 0 2 3 0 1 2 0 0 1 0 4 1 1 2 1 1 0 0 1 1 0 1 0 0 1 0 1 0 0 0 1 1 0 1 0 0 1 0 0 1 1 0 1 2 0 4 0 3 1 6 0 1 1 0 0 0 0 4 0 0 0 0 0 0 1 0 0 1 7 1 1 1 0 1 0 1 0 1 1 0 0 1 1 1 3 0 1 0 1 0 0 1 1 2 2 0 1 1 0 0 1 4 1 2 0 0 0 3 0 0 2 1 0 2 0 0 0 1 1 0 0 2 0 0 0 0 1 1 0 1 0 1 6 1 1 ...
output:
737899
result:
ok 1 number(s): "737899"
Test #7:
score: 0
Accepted
time: 62ms
memory: 3724kb
input:
12000 10000 1 1 0 0 1 0 2 1 3 0 0 1 0 3 1 1 0 1 1 1 1 1 2 1 0 1 2 1 0 1 2 0 5 1 1 1 0 2 0 1 0 1 0 3 2 0 1 0 1 1 2 1 0 0 1 1 0 1 0 0 0 1 0 1 0 1 0 4 0 1 3 1 0 0 1 0 1 2 1 0 0 1 1 0 2 1 1 0 1 0 1 0 0 2 1 1 3 0 1 1 1 0 0 0 1 1 1 0 3 0 0 0 2 0 0 0 1 0 2 0 1 1 1 0 0 1 0 1 0 2 0 0 0 0 0 0 0 1 0 1 0 0 4 1 ...
output:
73685347
result:
ok 1 number(s): "73685347"
Test #8:
score: 0
Accepted
time: 568ms
memory: 3932kb
input:
36000 30000 0 3 4 1 2 1 1 0 0 1 1 0 1 0 2 1 0 0 0 0 2 1 0 2 0 0 0 0 0 1 1 4 1 4 0 0 2 0 0 0 1 1 0 0 1 1 0 1 0 0 0 0 1 1 0 3 1 1 1 0 0 0 0 0 0 1 2 0 2 3 0 0 0 0 3 1 0 0 0 1 0 1 2 0 0 2 0 1 0 0 2 1 1 0 3 1 6 0 0 1 1 2 0 1 2 0 0 1 0 1 1 0 0 1 0 0 0 1 0 2 0 1 1 1 0 0 5 2 0 5 1 0 0 0 0 1 1 1 8 0 1 1 0 1 ...
output:
658813003
result:
ok 1 number(s): "658813003"
Test #9:
score: -100
Time Limit Exceeded
input:
200000 200000 0 1 1 1 1 1 0 1 0 3 1 0 0 1 1 0 1 1 1 2 3 0 1 0 1 0 2 5 0 1 1 4 1 1 0 0 0 0 0 0 2 1 0 0 2 1 1 2 0 3 0 1 3 0 1 1 1 0 1 0 1 2 0 1 1 0 0 2 2 1 0 1 1 2 4 1 0 2 0 5 1 2 0 0 1 0 2 3 1 0 1 1 1 1 0 0 0 5 1 0 0 1 2 1 1 0 0 0 1 0 0 1 2 1 0 0 2 1 2 3 0 0 3 1 0 1 0 0 1 1 1 0 1 0 1 0 0 1 0 0 1 1 1 ...