QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#511595 | #5384. Floppy Music | darrkeer | WA | 0ms | 3764kb | C++14 | 1.2kb | 2024-08-10 06:12:17 | 2024-08-10 06:12:17 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
constexpr int INF = 1e9;
void solve() {
int t, n; cin >> t >> n;
vector<int> v(n);
for(int i=0; i<n; ++i) {
int a, b; cin >> a >> b;
v[i] = b - a;
}
vector<vector<int>> dp(n, vector<int>(t + 1, INF));
dp[0][v[0]] = v[0];
dp[0][0] = v[0];
for(int i=0; i<n - 2; ++i) {
for(int j=0; j<=t; ++j) {
if(dp[i][j] == INF) {
continue;
}
int len = dp[i][j];
int r = j + v[i + 1];
if(r <= t) {
dp[i + 1][r] = min({dp[i + 1][r], r, len});
}
if(j < v[i + 1] && v[i + 1] + len - j <= t) {
dp[i + 1][0] = min({dp[i + 1][0], v[i + 1] + len - j});
} else {
int l = j - v[i + 1];
dp[i + 1][l] = min({dp[i + 1][l], len});
}
}
}
int mn = INF;
for(int j=0; j<=t; ++j) {
mn = min(mn, dp[n - 1][j]);
}
if(mn > t) {
cout << "impossible\n";
exit(0);
}
}
int main() {
int f; cin >> f;
for(int i=0; i<f; ++i) {
solve();
}
cout << "possible\n";
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3764kb
input:
1 6 2 0 4 6 12
output:
impossible
result:
wrong answer 1st lines differ - expected: 'possible', found: 'impossible'