QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#584966#140. Palembang Bridges isirazeev9 8ms3892kbC++202.9kb2024-09-23 18:03:252024-09-23 18:03:27

Judging History

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

  • [2024-09-23 18:03:27]
  • 评测
  • 测评结果:9
  • 用时:8ms
  • 内存:3892kb
  • [2024-09-23 18:03:25]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
#define int long long

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    int k, n;
    cin >> k >> n;
    char p[n], q[n];
    int s[n], t[n];
    for (int i = 0; i < n; i++) cin >> p[i] >> s[i] >> q[i] >> t[i];
    int res = (int) 1e18;
    set<int> all;
    vector<int> ALL;
    for (int i = 0; i < n; i++) {
        if (s[i] < t[i]) swap(s[i], t[i]);
        all.insert(t[i]), all.insert(s[i]);
        if (p[i] != q[i])
            ALL.emplace_back(s[i]), ALL.emplace_back(t[i]);
    }
    if (k == 1) {
        sort(ALL.begin(), ALL.end());
        int x = 0;
        for (int i = 0; i < n; i++) x += s[i] + t[i];
        x /= 2 * n;
        int cur_res = 0;
        for (int i = 0; i < n; i++) {
            if (p[i] == q[i]) {
                cur_res += s[i] - t[i];
                continue;
            }
            int a1 = 0;
            if (x < t[i]) a1 += t[i] - x + s[i] - x + 1;
            else if (x > s[i]) a1 += x - s[i] + x - t[i] + 1;
            else a1 += s[i] - t[i] + 1;
            cur_res += a1;
        }
        res = min(res, cur_res);
        x = ALL[(int) ALL.size() / 2];
        cur_res = 0;
        for (int i = 0; i < n; i++) {
            if (p[i] == q[i]) {
                cur_res += s[i] - t[i];
                continue;
            }
            int a1 = 0;
            if (x < t[i]) a1 += t[i] - x + s[i] - x + 1;
            else if (x > s[i]) a1 += x - s[i] + x - t[i] + 1;
            else a1 += s[i] - t[i] + 1;
            cur_res += a1;
        }
        res = min(res, cur_res);
        x = ALL[((int) ALL.size() + 1) / 2];
        cur_res = 0;
        for (int i = 0; i < n; i++) {
            if (p[i] == q[i]) {
                cur_res += s[i] - t[i];
                continue;
            }
            int a1 = 0;
            if (x < t[i]) a1 += t[i] - x + s[i] - x + 1;
            else if (x > s[i]) a1 += x - s[i] + x - t[i] + 1;
            else a1 += s[i] - t[i] + 1;
            cur_res += a1;
        }
        res = min(res, cur_res);
        cout << res;
        return 0;
    }
    for (int x: all) {
        for (int y: all) {
            int cur_res = 0;
            for (int i = 0; i < n; i++) {
                if (p[i] == q[i]) {
                    cur_res += s[i] - t[i];
                    continue;
                }
                int a1 = 0, a2 = 0;
                if (x < t[i]) a1 += t[i] - x + s[i] - x + 1;
                else if (x > s[i]) a1 += x - s[i] + x - t[i] + 1;
                else a1 += s[i] - t[i] + 1;
                if (y < t[i]) a2 += t[i] - y + s[i] - y + 1;
                else if (y > s[i]) a2 += y - s[i] + y - t[i] + 1;
                else a2 += s[i] - t[i] + 1;
                cur_res += min(a1, a2);
            }
            res = min(res, cur_res);
        }
    }
    cout << res;
    return 0;
}

详细

Subtask #1:

score: 0
Runtime Error

Test #1:

score: 0
Runtime Error

input:

1 1
B 426311872 B 741424667

output:


result:


Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 9
Accepted

Test #22:

score: 9
Accepted
time: 0ms
memory: 3492kb

input:

2 1
B 822190955 B 309099167

output:

513091788

result:

ok single line: '513091788'

Test #23:

score: 9
Accepted
time: 7ms
memory: 3856kb

input:

2 100
A 699479271 B 699479270
B 999432953 A 999432956
A 657124443 B 657124444
B 928721383 A 928721383
B 809218485 A 809218487
B 220719335 A 220719338
B 93242937 A 93242943
A 566737518 B 566737523
A 751211620 B 751211614
B 799605314 A 799605321
A 634052514 B 634052513
B 681923789 A 681923799
B 377862...

output:

22963819679

result:

ok single line: '22963819679'

Test #24:

score: 9
Accepted
time: 0ms
memory: 3608kb

input:

2 100
A 1000000000 B 1000000000
B 500000000 A 500000000
B 0 A 0
A 500000000 B 500000000
A 500000000 B 500000000
A 500000000 B 500000000
A 500000000 B 500000000
A 1000000000 B 1000000000
A 1000000000 B 1000000000
B 0 A 0
A 500000000 B 500000000
A 1000000000 B 1000000000
B 500000000 A 500000000
B 5000...

output:

27000000100

result:

ok single line: '27000000100'

Test #25:

score: 9
Accepted
time: 7ms
memory: 3556kb

input:

2 100
A 500000001 B 500000000
A 1 B 0
B 999999999 A 1000000000
A 500000003 B 500000002
B 500000005 A 500000004
A 3 B 2
B 5 A 4
A 999999998 B 999999997
B 500000007 A 500000006
B 999999995 A 999999996
B 7 A 6
A 500000009 B 500000008
B 999999994 A 999999993
A 499999991 B 499999990
B 999999991 A 9999999...

output:

30999998022

result:

ok single line: '30999998022'

Test #26:

score: 9
Accepted
time: 0ms
memory: 3604kb

input:

2 4
B 55 B 78
A 21 A 97
B 92 B 92
B 84 B 74

output:

109

result:

ok single line: '109'

Test #27:

score: 9
Accepted
time: 0ms
memory: 3556kb

input:

2 100
A 1 B 1
A 1 B 1
A 1 B 1
B 1 A 0
B 0 A 0
A 1 B 0
A 0 B 0
B 1 A 1
B 1 A 1
B 0 A 0
A 1 A 1
A 1 B 0
B 0 A 0
B 1 A 1
B 1 A 0
B 1 A 0
A 1 B 0
A 1 B 1
B 1 A 1
B 1 B 0
B 0 A 1
A 1 B 1
B 1 A 0
B 0 A 1
B 0 A 0
A 1 B 0
A 1 B 1
B 0 A 1
A 1 B 0
B 1 A 1
B 1 A 1
A 1 B 1
B 0 A 0
A 1 B 0
A 0 B 1
B 0 A 0
A 1 A ...

output:

134

result:

ok single line: '134'

Test #28:

score: 9
Accepted
time: 8ms
memory: 3840kb

input:

2 100
A 830663645 B 149522781
A 91020617 A 136114869
A 976752072 B 489083479
A 723475760 B 425258491
B 343608279 A 670899746
A 948111864 B 835020012
B 541673521 A 177220771
B 47989541 A 856054452
A 899383900 B 515311822
B 210600075 A 430126441
A 389002944 B 805377377
A 59969611 B 181903236
B 2100061...

output:

38368426380

result:

ok single line: '38368426380'

Test #29:

score: 9
Accepted
time: 2ms
memory: 3552kb

input:

2 61
B 421247 A 136386
B 577338 A 575018
A 590049 B 713374
B 707177 A 639019
B 88729 B 547265
A 609888 B 534260
B 718179 A 724517
A 314007 B 466852
A 943926 B 122653
A 203876 B 174784
A 921491 B 105450
A 231798 A 227899
B 910090 A 511702
A 611315 B 54073
A 466988 A 13202
A 535718 B 404074
A 742249 B...

output:

22682805

result:

ok single line: '22682805'

Test #30:

score: 9
Accepted
time: 4ms
memory: 3552kb

input:

2 74
B 882053752 A 484125527
B 365288128 A 966242196
A 898572614 B 833287499
B 503717014 A 522767856
B 896307119 A 383401506
B 441952771 A 170666881
B 533706597 A 587785410
A 944236304 B 784216408
B 539852944 A 2899025
A 543184591 B 320826476
B 835430009 A 129002850
B 474888334 A 348197537
B 1389952...

output:

27253941365

result:

ok single line: '27253941365'

Test #31:

score: 9
Accepted
time: 0ms
memory: 3548kb

input:

2 100
B 0 A 1000000000
B 1000000000 A 0
A 0 B 1000000000
A 1000000000 B 0
A 0 B 1000000000
B 0 A 1000000000
A 1000000000 B 0
A 1000000000 B 0
B 0 A 1000000000
A 0 B 1000000000
A 1000000000 B 0
A 0 B 1000000000
B 1000000000 A 0
B 1000000000 A 0
B 0 A 1000000000
A 1000000000 B 0
A 1000000000 B 0
A 100...

output:

100000000100

result:

ok single line: '100000000100'

Test #32:

score: 9
Accepted
time: 7ms
memory: 3628kb

input:

2 100
A 6749046 B 3359864
A 13741638 B 13682786
B 23339341 A 26650025
A 38142196 B 34007241
A 40375972 B 42863354
A 59569434 B 51459009
B 65829926 A 62359300
B 73417555 A 73466413
A 81029817 B 84425918
B 99092259 A 97204366
B 103900241 A 109835720
B 118829851 A 117967463
A 123398728 B 128836974
B 13...

output:

25026097994

result:

ok single line: '25026097994'

Test #33:

score: 9
Accepted
time: 8ms
memory: 3556kb

input:

2 100
A 0 B 1000000000
B 1 A 999999999
B 999999998 A 2
B 3 A 999999997
B 4 A 999999996
A 5 B 999999995
B 6 A 999999994
B 7 A 999999993
B 999999992 A 8
B 9 A 999999991
A 10 B 999999990
B 11 A 999999989
A 12 B 999999988
B 13 A 999999987
B 999999986 A 14
A 15 B 999999985
B 999999984 A 16
A 999999983 B ...

output:

99999990200

result:

ok single line: '99999990200'

Subtask #4:

score: 0
Time Limit Exceeded

Dependency #3:

100%
Accepted

Test #34:

score: 32
Accepted
time: 1ms
memory: 3892kb

input:

2 1000
A 1 B 1
B 0 A 0
B 0 A 1
A 1 B 1
B 0 A 1
B 0 A 1
A 1 B 0
B 0 A 0
A 0 B 1
A 1 B 0
B 0 A 0
A 0 B 1
A 1 B 0
B 1 A 1
A 0 B 1
A 1 B 1
A 1 B 0
A 1 B 1
B 0 A 0
A 0 B 1
B 1 A 1
A 0 B 0
B 0 A 0
B 0 A 0
B 1 A 0
B 1 A 0
B 0 A 1
B 1 A 0
A 1 B 1
B 1 A 0
A 1 B 1
B 0 A 0
A 1 B 1
B 1 A 0
B 0 A 1
A 1 B 1
B 0 A...

output:

1508

result:

ok single line: '1508'

Test #35:

score: 0
Time Limit Exceeded

input:

2 1000
B 717798362 A 717798355
B 145329556 A 145329556
A 90842768 B 90842766
A 190490307 B 190490306
A 353148284 B 353148284
A 592596931 B 592596929
B 339344699 A 339344704
A 7836475 B 7836470
A 612202811 B 612202820
A 583480096 B 583480102
A 592358042 B 592358045
B 234483707 A 234483712
B 549007793...

output:


result:


Subtask #5:

score: 0
Skipped

Dependency #4:

0%