QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#107723 | #5386. Hero Power | PetroTarnavskyi# | AC ✓ | 46ms | 23284kb | C++17 | 1.7kb | 2023-05-22 17:25:35 | 2023-05-22 17:25:37 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define MP make_pair
#define PB push_back
#define F first
#define S second
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
const int INF = 474'747'474;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n, p;
cin >> n >> p;
vector<int> t(n), l(p), r(p);
for (int& ti : t) {
cin >> ti;
}
FOR(i, 0, p) {
cin >> l[i] >> r[i];
}
p++;
l.push_back(INF);
r.push_back(INF + 1);
vector charge(p, vector<int>(n));
FOR(i, 0, p) {
int j = i, s = 0;
FOR(x, 0, n) {
if (t[x] < l[i]) {
continue;
}
while (l[j + 1] <= t[x]) {
s += r[j] - l[j];
j++;
assert(j + 1 < p);
}
charge[i][x] = s + min(t[x], r[j]) - l[j];
}
}
vector f(p, vector<int>(p));
vector<int> lastPoint(p);
FOR(j, 0, p) {
lastPoint[j] = lower_bound(ALL(t), l[j]) - t.begin() - 1;
}
FOR(i, 0, p) {
FOR(j, i + 1, p) {
int firstPoint = j == 0 ? 0 : lastPoint[j - 1] + 1;
int low = 0, high = n + 1;
while (high - low > 1) {
int mid = (low + high) / 2;
bool ok = false;
FOR(pt, max(mid - 1, firstPoint), lastPoint[j] + 1) {
ok |= charge[i][pt - mid + 1] > t[pt] - t[pt - mid + 1];
}
if (ok) {
low = mid;
}
else {
high = mid;
}
}
f[i][j] = low;
}
}
vector dp(p, -INF);
dp[0] = 0;
FOR(i, 0, p) {
FOR(j, i + 1, p) {
dp[j] = max(dp[j], dp[i] + f[i][j]);
}
}
cout << dp.back() + n << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3356kb
input:
3 1 0 10 20 0 10
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 2ms
memory: 3352kb
input:
6 1 0 10 20 26 40 50 0 40
output:
9
result:
ok single line: '9'
Test #3:
score: 0
Accepted
time: 2ms
memory: 3396kb
input:
10 2 0 10 20 30 40 50 60 70 80 90 0 40 70 80
output:
14
result:
ok single line: '14'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3432kb
input:
19 2 1000 2000 3000 4000 5000 6000 7000 8000 9000 10000 11000 15000 17000 19000 21000 23000 25000 27000 29000 2000 4000 7000 10000
output:
23
result:
ok single line: '23'
Test #5:
score: 0
Accepted
time: 2ms
memory: 3356kb
input:
15 2 0 1000 2000 2500 3000 3500 5000 5500 6000 6500 7000 10000 14000 14500 15000 0 2000 6500 10000
output:
22
result:
ok single line: '22'
Test #6:
score: 0
Accepted
time: 36ms
memory: 21396kb
input:
50000 91 0 11 109 139 239 300 445 596 724 897 1052 1169 1288 1487 1540 1555 1698 1742 1795 1865 1977 2085 2261 2316 2408 2594 2727 2759 2819 2993 3003 3087 3101 3222 3375 3481 3486 3575 3661 3680 3703 3812 3908 3927 4026 4054 4060 4257 4374 4409 4465 4623 4742 4926 5056 5079 5222 5333 5493 5582 5729...
output:
72211
result:
ok single line: '72211'
Test #7:
score: 0
Accepted
time: 46ms
memory: 23240kb
input:
50000 100 0 56 89 116 293 464 493 624 754 888 932 1085 1143 1321 1474 1614 1627 1675 1756 1827 1846 1978 2125 2142 2325 2384 2559 2638 2669 2810 2945 3068 3225 3255 3313 3394 3505 3632 3744 3804 3962 3995 4136 4291 4362 4441 4573 4613 4795 4942 5047 5137 5288 5466 5564 5720 5878 5897 6042 6134 6187 ...
output:
72039
result:
ok single line: '72039'
Test #8:
score: 0
Accepted
time: 41ms
memory: 23284kb
input:
50000 100 0 144 148 240 429 583 752 862 868 881 969 1088 1210 1318 1384 1454 1619 1787 1817 1967 2152 2300 2393 2523 2653 2687 2815 2935 3005 3185 3302 3465 3590 3592 3752 3868 4057 4119 4203 4266 4317 4380 4398 4408 4552 4676 4762 4871 4909 5066 5166 5232 5290 5383 5532 5684 5766 5965 6026 6069 619...
output:
72044
result:
ok single line: '72044'
Test #9:
score: 0
Accepted
time: 3ms
memory: 3520kb
input:
5000 1 0 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5...
output:
9999
result:
ok single line: '9999'
Test #10:
score: 0
Accepted
time: 2ms
memory: 3380kb
input:
3 1 0 1 2 0 1
output:
4
result:
ok single line: '4'
Test #11:
score: 0
Accepted
time: 2ms
memory: 3320kb
input:
9 2 0 1000 4000 5000 6000 16000 21000 26000 31000 0 1000 6000 16000
output:
12
result:
ok single line: '12'
Test #12:
score: 0
Accepted
time: 2ms
memory: 3360kb
input:
10 3 0 1000 4000 4500 5000 6000 16000 21000 26000 31000 0 1000 4000 5000 6000 16000
output:
14
result:
ok single line: '14'
Test #13:
score: 0
Accepted
time: 2ms
memory: 3388kb
input:
9 2 0 1 2 3 1002 20000 25000 30000 31000 0 1 3 1002
output:
11
result:
ok single line: '11'
Test #14:
score: 0
Accepted
time: 0ms
memory: 3448kb
input:
9 3 0 1000 2000 3000 4000 5000 6001 8000 9000 0 1000 3000 4000 6001 8000
output:
13
result:
ok single line: '13'
Test #15:
score: 0
Accepted
time: 1ms
memory: 3396kb
input:
7 2 0 5000 6000 7000 8000 8999 9000 0 5000 8999 9000
output:
13
result:
ok single line: '13'
Test #16:
score: 0
Accepted
time: 16ms
memory: 11156kb
input:
20000 100 0 100 200 300 400 500 600 700 800 900 1000 1100 1200 1300 1400 1500 1600 1700 1800 1900 2000 2100 2200 2300 2400 2500 2600 2700 2800 2900 3000 3100 3200 3300 3400 3500 3600 3700 3800 3900 4000 4100 4200 4300 4400 4500 4600 4700 4800 4900 5000 5100 5200 5300 5400 5500 5600 5700 5800 5900 60...
output:
30000
result:
ok single line: '30000'
Test #17:
score: 0
Accepted
time: 16ms
memory: 11100kb
input:
20000 100 0 100 200 300 400 500 600 700 800 900 1000 1100 1200 1300 1400 1500 1600 1700 1800 1900 2000 2100 2200 2300 2400 2500 2600 2700 2800 2900 3000 3100 3200 3300 3400 3500 3600 3700 3800 3900 4000 4100 4200 4300 4400 4500 4600 4700 4800 4900 5000 5100 5200 5300 5400 5500 5600 5700 5800 5900 60...
output:
30000
result:
ok single line: '30000'
Test #18:
score: 0
Accepted
time: 39ms
memory: 23260kb
input:
50000 100 62 156 251 314 401 497 580 659 759 821 898 991 1062 1145 1232 1301 1393 1463 1559 1628 1715 1776 1868 1958 2035 2113 2191 2291 2385 2477 2566 2654 2724 2822 2921 2994 3081 3178 3246 3311 3374 3437 3521 3603 3695 3765 3830 3925 4009 4099 4173 4241 4309 4379 4468 4558 4632 4692 4764 4862 494...
output:
74947
result:
ok single line: '74947'
Test #19:
score: 0
Accepted
time: 2ms
memory: 3364kb
input:
7 3 0 100 101 102 103 300 301 0 100 101 102 103 300
output:
12
result:
ok single line: '12'
Test #20:
score: 0
Accepted
time: 42ms
memory: 23272kb
input:
50000 100 587 1450 2487 3479 4551 5643 6477 7437 8103 9063 9765 10849 11660 12290 12905 13799 14401 15249 16338 17432 18320 19009 20010 20817 21903 22509 23312 24104 24862 25589 26623 27377 28041 28577 29534 30441 31279 31845 32944 33754 34262 35232 36331 36934 37749 38274 38831 39688 40530 41558 42...
output:
74956
result:
ok single line: '74956'