QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#584963 | #140. Palembang Bridges | isirazeev | 9 | 9ms | 3828kb | C++20 | 2.9kb | 2024-09-23 18:02:35 | 2024-09-23 18:02:35 |
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]);
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
Wrong Answer
Test #1:
score: 8
Accepted
time: 0ms
memory: 3772kb
input:
1 1 B 426311872 B 741424667
output:
315112795
result:
ok single line: '315112795'
Test #2:
score: 8
Accepted
time: 1ms
memory: 3540kb
input:
1 1000 A 1000000000 B 1000000000 B 1000000000 A 1000000000 A 500000000 B 500000000 A 1000000000 B 1000000000 B 0 A 0 A 500000000 B 500000000 B 0 A 0 A 1000000000 B 1000000000 A 500000000 B 500000000 A 1000000000 B 1000000000 B 1000000000 A 1000000000 A 0 B 0 B 0 A 0 B 0 A 0 A 500000000 B 500000000 B...
output:
659000001000
result:
ok single line: '659000001000'
Test #3:
score: 8
Accepted
time: 1ms
memory: 3728kb
input:
1 1000 A 500000001 B 500000000 A 500000002 B 500000003 A 500000005 B 500000004 A 1 B 0 B 500000007 A 500000006 A 500000009 B 500000008 B 500000010 A 500000011 B 1000000000 A 999999999 A 3 B 2 B 499999988 A 499999989 A 999999998 B 999999997 B 4 A 5 B 7 A 6 A 9 B 8 A 10 B 11 B 999999996 A 999999995 A ...
output:
649999819818
result:
ok single line: '649999819818'
Test #4:
score: 8
Accepted
time: 0ms
memory: 3828kb
input:
1 4 B 90 B 72 A 68 A 90 A 15 A 42 A 45 A 15
output:
97
result:
ok single line: '97'
Test #5:
score: 8
Accepted
time: 1ms
memory: 3640kb
input:
1 1000 A 0 B 1 A 1 B 0 A 0 B 1 B 0 A 0 B 1 B 1 B 0 A 0 A 1 B 1 A 1 B 1 A 1 B 0 A 0 B 1 A 0 B 0 B 1 A 1 B 0 A 0 B 0 A 0 A 1 B 0 A 1 B 0 B 1 A 0 B 0 A 0 A 1 B 1 A 1 B 1 B 0 A 1 B 0 A 1 A 0 B 1 B 0 A 1 A 1 B 0 A 1 B 1 B 1 A 0 B 1 A 0 B 1 A 0 A 1 B 0 A 0 B 1 A 0 B 1 A 0 B 0 B 0 A 0 A 1 B 1 B 0 A 1 B 0 A...
output:
1969
result:
ok single line: '1969'
Test #6:
score: 0
Wrong Answer
time: 1ms
memory: 3724kb
input:
1 1000 A 598246 B 85766 B 457924 A 841963 B 107690 A 39924 B 814042 A 328853 B 518897 A 548739 B 633776 A 181927 A 985484 B 773931 A 698975 B 526021 A 846547 B 258759 B 778661 A 181322 B 131489 A 151052 A 669218 B 314136 B 562707 A 887236 B 47953 A 880429 A 251615 B 488724 B 734021 A 487209 B 492935...
output:
497404135
result:
wrong answer 1st lines differ - expected: '497401257', found: '497404135'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 9
Accepted
Test #22:
score: 9
Accepted
time: 0ms
memory: 3824kb
input:
2 1 B 822190955 B 309099167
output:
513091788
result:
ok single line: '513091788'
Test #23:
score: 9
Accepted
time: 7ms
memory: 3796kb
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: 3492kb
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: 8ms
memory: 3800kb
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: 3748kb
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: 3624kb
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: 9ms
memory: 3540kb
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: 3ms
memory: 3648kb
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: 3532kb
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: 3596kb
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: 3544kb
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: 5ms
memory: 3604kb
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: 3812kb
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%