ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#203177 | #3545. game | yllcm | 100 | 1581ms | 16792kb | C++ | 2.0kb | 2024-02-20 09:14:06 | 2024-02-20 13:43:07 |
answer
#include<bits/stdc++.h>
#define ll long long
#define db double
#define ull unsigned long long
#define pb push_back
#define pii pair<int, int>
#define FR first
#define SE second
#define int long long
using namespace std;
inline int read() {
int x = 0; bool op = false;
char c = getchar();
while(!isdigit(c))op |= (c == '-'), c = getchar();
while(isdigit(c))x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
return op ? -x : x;
}
const int N = 5e5 + 10;
const int INF = 1e18;
int n, m, x;
int a[N], b[N], c[N], d[N];
signed main() {
n = read(); m = read(); x = read();
for(int i = 1; i <= n; i++)a[i] = read();
for(int i = 1; i <= m; i++)b[i] = read();
int cnt1 = 0, cnt2 = 0;
int mn1 = INF, mn2 = INF;
for(int i = 1; i <= n; i++)mn1 = min(mn1, a[i]);
for(int i = 1; i <= m; i++)mn2 = min(mn2, b[i]);
for(int i = 1; i <= n; i++)a[i] -= mn1;
for(int i = 1; i <= m; i++)b[i] -= mn2;
for(int i = 1; i <= n; i++)cnt1 += a[i] / x, a[i] %= x;
for(int i = 1; i <= m; i++)cnt2 += b[i] / x, b[i] %= x;
sort(a + 1, a + 1 + n); sort(b + 1, b + 1 + m);
int g = __gcd(n, m), ans = INF;
// printf("%d %d\n", cnt1, cnt2);
// for(int i = 1; i <= n; i++)printf("%d ", a[i]); putchar('\n');
// for(int i = 1; i <= m; i++)printf("%d ", b[i]); putchar('\n');
for(int i = 0; i < g; i++)c[i] = d[i] = INF;
for(int i = 1; i <= n; i++) {
int &v = c[((i - cnt1) % g + g) % g];
v = min(v, x - (a[i % n + 1] - a[i] + (i == n) * x));
}
for(int i = 1; i <= m; i++) {
int &v = d[((i - cnt2) % g + g) % g];
v = min(v, x - (b[i % m + 1] - b[i] + (i == m) * x));
}
for(int i = 0; i < g; i++)ans = min(ans, c[i] + d[i]);
// for(int i = 1; i <= n; i++) {
// for(int j = 1; j <= m; j++) {
// int val = (i - cnt1) - (j - cnt2);
// val = (val % g + g) % g;
// if(val == 0)ans = min(ans, 2 * x - (a[i % n + 1] - a[i] + x) % x - (b[j % m + 1] - b[j] + x) % x);
// }
// }
printf("%lld\n", ans);
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 5
Accepted
time: 0ms
memory: 1184kb
input:
2 2 1000000 948364364 463781920 331555568 90472908
output:
500216
result:
ok single line: '500216'
Test #2:
score: 5
Accepted
time: 0ms
memory: 1180kb
input:
2 2 999999 170194963 639025544 941031700 349446447
output:
754794
result:
ok single line: '754794'
Test #3:
score: 5
Accepted
time: 0ms
memory: 1184kb
input:
2 2 999999 745738604 245622179 348420894 341088700
output:
784723
result:
ok single line: '784723'
Test #4:
score: 5
Accepted
time: 0ms
memory: 1180kb
input:
15 5 17 12 10 13 1 3 1 9 2 11 6 13 7 14 1 19 8 1 18 4 17
output:
24
result:
ok single line: '24'
Test #5:
score: 5
Accepted
time: 0ms
memory: 1172kb
input:
16 8 17 4 16 9 12 16 5 8 16 14 7 12 7 14 5 19 9 8 15 10 8 14 18 12 20
output:
26
result:
ok single line: '26'
Test #6:
score: 5
Accepted
time: 0ms
memory: 1184kb
input:
19 20 500 5 17 1 3 16 17 2 4 5 5 8 17 18 4 19 16 6 3 6 18 18 7 3 3 2 11 20 2 15 18 5 1 8 3 13 14 9 1...
output:
37
result:
ok single line: '37'
Test #7:
score: 5
Accepted
time: 0ms
memory: 1200kb
input:
1000 999 888 491 229 618 639 918 607 879 627 40 450 609 102 970 122 55 717 663 195 53 340 843 110 55...
output:
1762
result:
ok single line: '1762'
Test #8:
score: 5
Accepted
time: 0ms
memory: 1188kb
input:
1000 100 888 462 65 621 497 985 149 716 505 779 724 917 685 478 828 939 297 673 878 624 800 351 108 ...
output:
1726
result:
ok single line: '1726'
Test #9:
score: 5
Accepted
time: 0ms
memory: 1184kb
input:
250 150 888 241 25 902 805 720 233 55 178 519 323 454 392 176 695 656 580 419 482 195 563 366 272 89...
output:
1730
result:
ok single line: '1730'
Test #10:
score: 5
Accepted
time: 90ms
memory: 5080kb
input:
1 500000 1000000000 747323127 963718212 806914589 212315576 835495436 183593413 939946203 376794181 ...
output:
999970751
result:
ok single line: '999970751'
Test #11:
score: 5
Accepted
time: 101ms
memory: 5084kb
input:
1 500000 100000000 4630340 368982591 319293019 73434682 151733468 679506573 811288048 303409690 8487...
output:
99997334
result:
ok single line: '99997334'
Test #12:
score: 5
Accepted
time: 90ms
memory: 5072kb
input:
1 500000 10000 468438890 347976444 571474658 289413154 883809085 190073689 924017413 702822268 63217...
output:
9999
result:
ok single line: '9999'
Test #13:
score: 5
Accepted
time: 167ms
memory: 16792kb
input:
500000 500000 71835378 7314070 4369749 848977 1317877 61094 6878144 111873 5880895 7440332 66981 488...
output:
19999744
result:
ok single line: '19999744'
Test #14:
score: 5
Accepted
time: 178ms
memory: 16792kb
input:
500000 500000 81835378 8428698 4888471 9643254 22055 505377 3347194 92679 42774 44252 6371168 12254 ...
output:
19999909
result:
ok single line: '19999909'
Test #15:
score: 5
Accepted
time: 176ms
memory: 16792kb
input:
500000 500000 91835378 7965302 66856 80768 95513 2515538 4045455 7535144 61772 30566 8063 173097 373...
output:
19999959
result:
ok single line: '19999959'
Test #16:
score: 5
Accepted
time: 167ms
memory: 8988kb
input:
500000 499999 91835378 7275977 54627 25295 8965 891981 732726 61503 33415 4674120 9806792 2644978 83...
output:
19999967
result:
ok single line: '19999967'
Test #17:
score: 5
Accepted
time: 176ms
memory: 8984kb
input:
500000 499995 91835378 79162 2846539 5451959 88097 9816274 14148 9133389 6742823 16061 9541679 61528...
output:
19999928
result:
ok single line: '19999928'
Test #18:
score: 5
Accepted
time: 163ms
memory: 8988kb
input:
500000 499990 91835378 10984 2655064 2566021 58742 74530 7720343 5793997 9200881 8488895 46364 57440...
output:
19999961
result:
ok single line: '19999961'
Test #19:
score: 5
Accepted
time: 166ms
memory: 8984kb
input:
500000 499980 91835378 6181126 4067356 47734 2325031 55266 2003629 303826 34060 17462 51832 96852 66...
output:
19999938
result:
ok single line: '19999938'
Test #20:
score: 5
Accepted
time: 107ms
memory: 7428kb
input:
500000 100000 71835378 509467 1551641 7950332 9369102 8460686 21976 8383224 4311353 6200608 9367026 ...
output:
19999758
result:
ok single line: '19999758'
Extra Test:
score: 0
Extra Test Passed