QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#24728 | #3502. Sightseeing in Kyoto | JohnAlfnov | 0 | 2ms | 3724kb | C++20 | 1.6kb | 2022-04-02 18:12:57 | 2022-04-30 06:32:25 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
struct xiaoxiong{
int yd,xd,mx;
xiaoxiong(int yd=0,int xd=0,int mx=0):yd(yd),xd(xd),mx(mx){}
bool operator<(const xiaoxiong &other)const{
return 1ll*yd*other.xd>1ll*other.yd*xd;
}
};
int a[100005],b[100005];
int nxt1[100005],pre1[100005];
int nxt2[100005],pre2[100005];
int hs[100005],ls[100005];
int main(){
int n,m;
cin>>n>>m;
for(int i=1;i<=n;++i)scanf("%d",&a[i]);
for(int i=1;i<=m;++i)scanf("%d",&b[i]);
set<xiaoxiong>se;
for(int i=1;i<=n;++i)nxt1[i]=i+1,pre1[i]=i-1;
for(int i=1;i<=m;++i)nxt2[i]=i+1,pre2[i]=i-1;
for(int i=1;i<n;++i){
se.emplace(a[i+1]-a[i],1,i+1);
}
for(int i=1;i<m;++i){
se.emplace(b[i+1]-b[i],1,n+i+1);
}
long long ans=0;
int ABC=1,ARC=1;
int AGC=n,AHC=m;
while(se.size()){
auto it=se.begin();
auto cu=*it;
se.erase(it);
if(cu.mx<=n){
int x=cu.mx;
hs[x]=1;
int L=pre1[x],R=nxt1[x];
nxt1[L]=R,pre1[R]=L;
if(L>0&&R<=n){
se.emplace(a[R]-a[L],R-L,R);
}
while(hs[ABC]&&ls[ARC]){
ans+=a[ABC];
++ARC;
}
while(hs[AGC]&&ls[AHC]){
ans+=a[AGC];
--AHC;
}
}else{
int x=cu.mx-n;
ls[x]=1;
int L=pre2[x],R=nxt2[x];
nxt2[L]=R,pre2[R]=L;
if(L>0&&R<=m){
se.emplace(b[R]-b[L],R-L,n+R);
}
while(hs[ABC]&&ls[ARC]){
ans+=b[ARC];
++ABC;
}
while(hs[AGC]&&ls[AHC]){
ans+=b[AHC];
--AGC;
}
}
}
assert(ABC==AGC||ARC==AHC);
if(ABC==AGC){
ans+=1ll*(AHC-ARC)*a[ABC];
}else{
ans+=1ll*(AGC-ABC)*b[AHC];
}
cout<<ans<<endl;
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 3724kb
input:
55 985 972919143 571703632 545299240 122906268 313605426 768197556 821161013 810382136 607096032 550926769 636584830 233641411 664075312 999513344 919939491 226167158 374405025 792842315 461126245 212582686 538315759 397667313 770583715 411616307 363120565 690544971 780156662 507283838 215368652 461...
output:
234213505644
result:
wrong answer 1st lines differ - expected: '144700753486', found: '234213505644'
Subtask #2:
score: 0
Dangerous Syscalls
Test #15:
score: 0
Dangerous Syscalls
input:
307 1278 1000 991 983 975 967 959 952 944 936 928 920 913 905 897 889 882 874 867 859 852 844 837 829 822 815 808 800 793 786 779 772 764 757 750 743 736 730 723 716 709 702 695 689 682 675 669 662 655 649 642 636 630 623 617 610 604 598 592 585 579 573 567 561 555 549 543 537 531 525 519 514 508 50...
output:
result:
Subtask #3:
score: 0
Skipped
Dependency #1:
0%