QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#511588 | #5384. Floppy Music | darrkeer | WA | 0ms | 3844kb | C++14 | 1.2kb | 2024-08-10 04:18:50 | 2024-08-10 04:18:51 |
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];
for(int i=0; i<n - 1; ++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";
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3600kb
input:
1 6 2 0 4 6 12
output:
possible
result:
ok single line: 'possible'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3800kb
input:
1 6 3 0 5 6 8 9 14
output:
impossible
result:
ok single line: 'impossible'
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3844kb
input:
1 10000 2 0 10000 990000 1000000
output:
impossible
result:
wrong answer 1st lines differ - expected: 'possible', found: 'impossible'