QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#120349#4270. Double Attendancebashkort#0 606ms3908kbC++204.0kb2023-07-06 16:57:202024-07-04 00:21:55

Judging History

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

  • [2024-07-04 00:21:55]
  • 评测
  • 测评结果:0
  • 用时:606ms
  • 内存:3908kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-06 16:57:20]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

constexpr int inf = 2e9 + 7;

void ckmax(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>> seg[2];
    vector<int> yy[2], dp[2], all;

    for (int t = 0; t < 2; ++t) {
        for (int i = 0; i < n[t]; ++i) {
            int l, r;
            cin >> l >> r;
            seg[t].emplace_back(l, r - 1);
            yy[t].push_back(l), yy[t].push_back(r - 1);
        }
        yy[t].push_back(0);
        sort(seg[t].begin(), seg[t].end());
        sort(yy[t].begin(), yy[t].end());
        yy[t].resize(unique(yy[t].begin(), yy[t].end()) - yy[t].begin());
        dp[t].assign(yy[t].size(), -inf);
    }

    all.resize(yy[0].size() + yy[1].size());
    merge(yy[0].begin(), yy[0].end(), yy[1].begin(), yy[1].end(), all.begin());
    all.resize(unique(all.begin(), all.end()) - all.begin());

    auto in = [&](int t, int i) -> int {
        auto it = lower_bound(seg[t].begin(), seg[t].end(), pair<int, int>{i, inf});
        if (it == seg[t].begin() || prev(it)->second < i) {
            return false;
        } else {
            return it - seg[t].begin();
        }
    };

    auto isl = [&](int s, int x) {
        int i = in(s, x);
        return i && seg[s][i - 1].first == x;
    };

    auto find = [&](int s, int x) -> int {
        return lower_bound(yy[s].begin(), yy[s].end(), x) - yy[s].begin();
    };

    dp[0][0] = isl(0, 0);

    int siz[2]{int(size(yy[0])), int(size(yy[1]))};

    for (int x : all) {
        for (int s = 0; s < 2; ++s) {
            int i = find(s, x);
            if (i >= size(yy[s]) || yy[s][i] != x) {
                continue;
            }
            int nxt = find(s, x + 1);
            if (nxt < siz[s]) {
                ckmax(dp[s][nxt], dp[s][i] + isl(s, yy[s][nxt]));
            }
            nxt = find(s ^ 1, x + k);
            if (nxt < siz[s ^ 1]) {
                ckmax(dp[s ^ 1][nxt], dp[s][i] + isl(s ^ 1, yy[s ^ 1][nxt]));
            }
            int cnt = 0;
            for (int t = 1; ; ++t) {
                int ns = s ^ (t & 1);
                int nx = x + k * t;
                if (!in(ns, nx)) {
                    break;
                } else {
                    cnt += 1;
                }
            }
            if (cnt > 0) {
                int del = cnt % 2 == 0;
                if (del) {
                    cnt -= 1;
                }
                int nx = x + k * cnt;
                int p = in(s ^ 1, nx);
                assert(p > 0);
                p -= 1;
                //assert(yy[s ^ 1][find(s ^ 1, nx)] == seg[s ^ 1][p].second);
                ckmax(dp[s ^ 1][find(s ^ 1, seg[s ^ 1][p].second)], dp[s][i] + cnt);
                if (del) {
                    cnt += 1;
                }
            }
            if (cnt > 1) {
                int del = cnt % 2 == 1;
                if (del) {
                    cnt -= 1;
                }
                int nx = x + k * cnt;
                int p = in(s, nx);
                assert(p > 0);
                p -= 1;
                //assert(yy[s][find(s, nx)] == seg[s][p].second);
                ckmax(dp[s][find(s, seg[s][p].second)], dp[s][i] + cnt);
                if (del) {
                    cnt += 1;
                }
            }
            for (int c : {cnt - 1, cnt, cnt + 1}) {
                if (c <= 0) {
                    continue;
                }
                int ns = s ^ (c & 1);
                int ni = find(ns, x + c * k);
                if (ni < siz[ns]) {
                    ckmax(dp[ns][ni], dp[s][i] + c);
                }
            }
        }
    }

    int ans = max(*max_element(dp[0].begin(), dp[0].end()), *max_element(dp[1].begin(), dp[1].end()));

    cout << ans << '\n';

    return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 5
Accepted
time: 0ms
memory: 3824kb

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: 0ms
memory: 3592kb

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: 0ms
memory: 3540kb

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:

19

result:

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

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Wrong Answer

Test #104:

score: 6
Accepted
time: 0ms
memory: 3780kb

input:

1 1 1
0 1
0 1

output:

1

result:

ok single line: '1'

Test #105:

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

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:

2000

result:

ok single line: '2000'

Test #106:

score: 0
Accepted
time: 606ms
memory: 3908kb

input:

2000 2000 249875
608195750 608695500
88455750 88955500
579210250 579710000
817091250 817591000
527736000 528235750
52473750 52973500
89955000 90454750
184407750 184907500
668165750 668665500
24487750 24987500
466266750 466766500
471764000 472263750
212393750 212893500
250874500 251374250
939530000 9...

output:

4000

result:

ok single line: '4000'

Test #107:

score: 0
Accepted
time: 605ms
memory: 3756kb

input:

2000 2000 249875
965017250 965517000
73963000 74462750
242878500 243378250
148925500 149425250
747126250 747626000
384307750 384807500
655172250 655672000
278360750 278860500
899050250 899550000
496251750 496751500
92953500 93453250
677661000 678160750
828085750 828585500
297351250 297851000
5887055...

output:

4000

result:

ok single line: '4000'

Test #108:

score: -6
Wrong Answer
time: 279ms
memory: 3736kb

input:

2000 2000 499500
428 429
764235000 765234000
511488000 512487000
291 292
585414000 586413000
127 128
819 820
727 728
233766000 234765000
643 644
234 235
326 327
432 433
218781000 219780000
10989000 11988000
805194000 806193000
283716000 284715000
965034000 966033000
632367000 633366000
824 825
454 4...

output:

3999

result:

wrong answer 1st lines differ - expected: '4000', found: '3999'

Subtask #4:

score: 0
Skipped

Dependency #1:

0%