QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#125947#4270. Double Attendancebashkort0 1ms3520kbC++201.6kb2023-07-17 23:17:342023-07-17 23:17:35

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-17 23:17:35]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:3520kb
  • [2023-07-17 23:17:34]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

void ckmin(int &x, int y) {
    if (x > y) {
        x = y;
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n[2], k;
    cin >> n[0] >> n[1] >> k;

    vector<pair<int, int>> s[2];
    s[0] = s[1] = {{-1, -1}};

    for (int t = 0; t < 2; ++t) {
        for (int i = 0; i < n[t]; ++i) {
            int l, r;
            cin >> l >> r;
            s[t].push_back({l, r - 1});
        }
    }

    auto find = [&](int t, int x) {
        return lower_bound(s[t].begin(), s[t].end(), pair{x + 1, 0});
    };

    auto in = [&](int t, int x) {
        return prev(find(t, x))->second >= x;
    };

    vector dp(2, vector<int>(n[0] + n[1] + 1, 2e9));
    dp[0][in(0, 0)] = 0;
    int ans = 0;

    for (int i = 0; i < n[0] + n[1]; ++i) {
        for (int m = 0; m < 2; ++m) {
            for (int t = 0; t < 2; ++t) {
                if (dp[t][i] > 1e9) {
                    continue;
                }
                int x = dp[t][i];
                auto p = find(t, x);
                if (p != s[t].end()) {
                    ckmin(dp[t][i + 1], p->first);
                }
                p = prev(p);
                int r = max<int>(x + k, p->second - k + 1);
                int add = find(t ^ 1, r) - find(t ^ 1, x + k) + in(t ^ 1, x + k);
                ckmin(dp[t ^ 1][i + add], r);
            }
        }
    }
    
    for (int x = 0; x <= n[0] + n[1]; ++x) {
        if (dp[0][x] < 2e9 || dp[1][x] < 2e9) {
            ans = x;
        }
    }

    cout << ans << '\n';

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 5
Accepted
time: 1ms
memory: 3432kb

input:

3 1 8
10 20
100 101
20 21
15 25

output:

3

result:

ok single line: '3'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3448kb

input:

1 5 3
1 100
1 2
2 3
3 4
4 5
5 6

output:

4

result:

ok single line: '4'

Test #3:

score: -5
Wrong Answer
time: 1ms
memory: 3436kb

input:

10 10 5
4 9
43 48
69 70
70 72
52 67
75 83
100 103
103 1501
10 27
28 40
5 7
27 29
30 39
40 42
42 45
67 80
0 5
45 59
10 20
22 23

output:

10

result:

wrong answer 1st lines differ - expected: '18', found: '10'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Wrong Answer

Test #104:

score: 6
Accepted
time: 1ms
memory: 3488kb

input:

1 1 1
0 1
0 1

output:

1

result:

ok single line: '1'

Test #105:

score: -6
Wrong Answer
time: 1ms
memory: 3520kb

input:

1 2000 2
999999996 1000000000
336 337
502 503
1906 1907
963 964
1351 1352
1795 1796
1510 1511
304 305
1930 1931
1735 1736
1469 1470
338 339
813 814
182 183
209 210
321 322
849 850
721 722
394 395
889 890
1758 1759
1440 1441
560 561
1470 1471
1916 1917
793 794
1366 1367
158 159
1602 1603
214 215
1119...

output:

5

result:

wrong answer 1st lines differ - expected: '2000', found: '5'

Subtask #4:

score: 0
Skipped

Dependency #1:

0%