ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#203189 | #3545. game | sjc061031 | 100 | 1700ms | 9084kb | C++11 | 993b | 2024-02-20 10:59:40 | 2024-02-20 13:44:30 |
answer
#include <bits/stdc++.h>
#define INF 1000000007
using namespace std;
int n,m,x,a[500010],b[500010],A[500010],B[500010];
signed main()
{
ios::sync_with_stdio(false);cin.tie(0);
cin>>n>>m>>x;
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=m;i++) cin>>b[i];
sort(a+1,a+n+1);sort(b+1,b+m+1);
int prea=a[1],preb=b[1];
for(int i=1;i<=n;i++) a[i]-=prea;
for(int i=1;i<=m;i++) b[i]-=preb;
int suma=0,sumb=0;
for(int i=1;i<=n;i++){
suma=(suma+a[i]/x)%n;
a[i]%=x;
}
for(int i=1;i<=m;i++){
sumb=(sumb+b[i]/x)%m;
b[i]%=x;
}
sort(a+1,a+n+1);sort(b+1,b+m+1);
int g=__gcd(n,m);
for(int i=0;i<g;i++){
A[i]=INF;B[i]=INF;
}
a[0]=0;a[n+1]=x;
for(int i=0;i<=n;i++){
int id=((suma+i)%n)%g;
A[id]=min(A[id],a[n-i]+(x-a[n-i+1]));
}
b[0]=0;b[m+1]=x;
for(int i=0;i<=m;i++){
int id=((sumb+i)%m)%g;
B[id]=min(B[id],b[m-i]+(x-b[m-i+1]));
}
int ans=2*INF;
for(int i=0;i<g;i++) ans=min(ans,A[i]+B[i]);
cout<<ans<<'\n';
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 5
Accepted
time: 1ms
memory: 1280kb
input:
2 2 1000000 948364364 463781920 331555568 90472908
output:
500216
result:
ok single line: '500216'
Test #2:
score: 5
Accepted
time: 0ms
memory: 1280kb
input:
2 2 999999 170194963 639025544 941031700 349446447
output:
754794
result:
ok single line: '754794'
Test #3:
score: 5
Accepted
time: 0ms
memory: 1284kb
input:
2 2 999999 745738604 245622179 348420894 341088700
output:
784723
result:
ok single line: '784723'
Test #4:
score: 5
Accepted
time: 0ms
memory: 1284kb
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: 1268kb
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: 1280kb
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: 1296kb
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: 1292kb
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: 1280kb
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: 94ms
memory: 3240kb
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: 99ms
memory: 3240kb
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: 118ms
memory: 3236kb
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: 213ms
memory: 9084kb
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: 182ms
memory: 9080kb
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: 184ms
memory: 9080kb
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: 177ms
memory: 5188kb
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: 166ms
memory: 5184kb
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: 175ms
memory: 5188kb
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: 182ms
memory: 5188kb
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: 109ms
memory: 4404kb
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