QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#511593#5384. Floppy MusicdarrkeerWA 7ms7132kbC++141.2kb2024-08-10 05:46:172024-08-10 05:46:18

Judging History

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

  • [2024-08-10 05:46:18]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:7132kb
  • [2024-08-10 05:46:17]
  • 提交

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: 3580kb

input:

1
6 2
0 4
6 12

output:

possible

result:

ok single line: 'possible'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3464kb

input:

1
6 3
0 5
6 8
9 14

output:

impossible

result:

ok single line: 'impossible'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3576kb

input:

1
10000 2
0 10000
990000 1000000

output:

possible

result:

ok single line: 'possible'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3680kb

input:

1
10000 2
1 10002
990000 1000000

output:

impossible

result:

ok single line: 'impossible'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3732kb

input:

1
1 2
1 2
3 4

output:

possible

result:

ok single line: 'possible'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3592kb

input:

1
1 2
1 2
3 5

output:

impossible

result:

ok single line: 'impossible'

Test #7:

score: 0
Accepted
time: 7ms
memory: 7132kb

input:

10
10000 100
22 78
86 112
165 200
283 368
441 506
542 565
576 597
683 776
875 958
1020 1111
1174 1242
1267 1352
1423 1472
1491 1585
1609 1704
1713 1779
1797 1849
1870 1899
1921 2005
2084 2103
2123 2157
2230 2303
2332 2400
2412 2463
2470 2484
2558 2591
2671 2753
2779 2851
2871 2926
2961 2991
3086 318...

output:

possible

result:

ok single line: 'possible'

Test #8:

score: 0
Accepted
time: 4ms
memory: 5208kb

input:

7
7982 63
5419 8609
12279 15901
21280 22127
25534 28854
32746 38025
43555 48911
53164 55072
58283 63842
66546 71475
76018 78894
83864 88900
93309 97796
102097 103772
104561 107998
111601 114622
117735 122757
124691 128199
131789 136151
137937 139849
141519 143338
143453 147152
147686 152946
154136 1...

output:

possible

result:

ok single line: 'possible'

Test #9:

score: -100
Wrong Answer
time: 0ms
memory: 5728kb

input:

6
8421 8
1140 1775
6665 9136
13822 19656
24852 29906
34476 37676
41940 42519
47990 51976
57202 60998
676 84
280 322
512 932
1233 1240
1262 1334
1464 1854
2139 2345
2423 2436
2601 2789
2808 2862
2937 3228
3307 3600
4067 4349
4817 5184
5310 5363
5769 5941
6082 6168
6492 6767
6931 7042
7205 7676
7744 7...

output:

possible

result:

wrong answer 1st lines differ - expected: 'impossible', found: 'possible'