QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#511588#5384. Floppy MusicdarrkeerWA 0ms3844kbC++141.2kb2024-08-10 04:18:502024-08-10 04:18:51

Judging History

你现在查看的是最新测评结果

  • [2024-08-10 04:18:51]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3844kb
  • [2024-08-10 04:18:50]
  • 提交

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";
}

Details

Tip: Click on the bar to expand more detailed information

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'