QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#107721 | #5384. Floppy Music | PetroTarnavskyi# | WA | 1ms | 3432kb | C++17 | 1.7kb | 2023-05-22 17:18:04 | 2023-05-22 17:18:05 |
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: 0
Wrong Answer
time: 1ms
memory: 3432kb
input:
1 6 2 0 4 6 12
output:
2
result:
wrong answer 1st lines differ - expected: 'possible', found: '2'