Submission #75698471


Source Code Expand

#include<bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define per(i,l,r) for(int i=(l);i>=(r);--i)

using namespace std;
const int N=5e5+10;
pii a[N];
int h,w,n,b[N],d[N],bc,dc;

signed main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>h>>w>>n; rep(i,1,n) cin>>a[i].fi>>a[i].se;
    sort(a+1,a+n+1); int s1=0,s2=0,m=0,i=1;
    while(i<=n){
        int j=i;bc=0;
        while(j<=n&&a[j].fi==a[i].fi) b[++bc]=a[j++].se;
        int cl=2*(b[bc]-1),cr=2*(w-b[1]),c4=min(cl,cr);
        s1+=cl;rep(k,1,bc-1) c4=min(c4,2*(b[k]-1)+2*(w-b[k+1]));
        s2+=c4;d[++dc]=w-1-c4;m++;i=j;
    }
    int ad=min(h-m,2ll); rep(k,1,ad) d[++dc]=w-1;
    int ans=s1,cur=0,mi=-1,val=0; sort(d+1,d+dc+1);
    rep(k,1,dc){cur+=d[k];if(!(k&1)&&(!val||s2+cur<mi)) mi=s2+cur,val=1;}
    if(val&&mi<ans) ans=mi; cout<<ans<<"\n";
    return 0;
}

Submission Info

Submission Time
Task C - Traveling Door-to-Door Salesman (Elevator)
User Fourier_WJY
Language C++23 (GCC 15.2.0)
Score 500
Code Size 967 Byte
Status AC
Exec Time 71 ms
Memory 10664 KiB

Compile Error

./Main.cpp: In function 'int main()':
./Main.cpp:28:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   28 |     if(val&&mi<ans) ans=mi; cout<<ans<<"\n";
      |     ^~
./Main.cpp:28:29: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   28 |     if(val&&mi<ans) ans=mi; cout<<ans<<"\n";
      |                             ^~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 2
AC × 55
Set Name Test Cases
Sample 00-sample-01.txt, 00-sample-02.txt
All 00-sample-01.txt, 00-sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 02-m-01.txt, 02-m-02.txt, 02-m-03.txt, 02-m-04.txt, 02-m-05.txt, 02-m-06.txt, 02-m-07.txt, 02-m-08.txt, 02-m-09.txt, 02-m-10.txt, 03-len-01.txt, 03-len-02.txt, 03-len-03.txt, 03-len-04.txt, 03-len-05.txt, 03-len-06.txt, 03-len-07.txt, 03-len-08.txt, 03-len-09.txt, 03-len-10.txt, 04-edge-01.txt, 04-edge-02.txt, 04-edge-03.txt, 04-edge-04.txt, 04-edge-05.txt, 04-edge-06.txt, 04-edge-07.txt, 04-edge-08.txt, 04-edge-09.txt, 05-gapmax-01.txt, 05-gapmax-02.txt, 05-gapmax-03.txt, 05-gapmax-04.txt, 05-gapmax-05.txt, 05-gapmax-06.txt, 05-gapmax-07.txt, 05-gapmax-08.txt, 05-gapmax-09.txt, 05-gapmax-10.txt, 05-gapmax-11.txt, 05-gapmax-12.txt, 05-gapmax-13.txt, 05-gapmax-14.txt, 05-gapmax-15.txt, 05-gapmax-16.txt
Case Name Status Exec Time Memory
00-sample-01.txt AC 2 ms 3448 KiB
00-sample-02.txt AC 1 ms 3536 KiB
01-01.txt AC 1 ms 3540 KiB
01-02.txt AC 46 ms 10540 KiB
01-03.txt AC 48 ms 10664 KiB
01-04.txt AC 52 ms 10588 KiB
01-05.txt AC 47 ms 10608 KiB
01-06.txt AC 8 ms 4436 KiB
01-07.txt AC 7 ms 4208 KiB
01-08.txt AC 70 ms 10588 KiB
02-m-01.txt AC 53 ms 10560 KiB
02-m-02.txt AC 55 ms 9332 KiB
02-m-03.txt AC 54 ms 8896 KiB
02-m-04.txt AC 54 ms 8912 KiB
02-m-05.txt AC 55 ms 8320 KiB
02-m-06.txt AC 53 ms 8236 KiB
02-m-07.txt AC 54 ms 8292 KiB
02-m-08.txt AC 54 ms 8304 KiB
02-m-09.txt AC 54 ms 8576 KiB
02-m-10.txt AC 58 ms 8820 KiB
03-len-01.txt AC 71 ms 10540 KiB
03-len-02.txt AC 60 ms 9512 KiB
03-len-03.txt AC 58 ms 9088 KiB
03-len-04.txt AC 56 ms 8872 KiB
03-len-05.txt AC 55 ms 8232 KiB
03-len-06.txt AC 53 ms 8284 KiB
03-len-07.txt AC 54 ms 8320 KiB
03-len-08.txt AC 54 ms 8320 KiB
03-len-09.txt AC 56 ms 8576 KiB
03-len-10.txt AC 53 ms 9000 KiB
04-edge-01.txt AC 71 ms 10432 KiB
04-edge-02.txt AC 54 ms 8912 KiB
04-edge-03.txt AC 69 ms 10456 KiB
04-edge-04.txt AC 52 ms 8868 KiB
04-edge-05.txt AC 61 ms 9328 KiB
04-edge-06.txt AC 54 ms 8876 KiB
04-edge-07.txt AC 47 ms 10624 KiB
04-edge-08.txt AC 53 ms 10664 KiB
04-edge-09.txt AC 51 ms 9428 KiB
05-gapmax-01.txt AC 53 ms 8232 KiB
05-gapmax-02.txt AC 53 ms 8236 KiB
05-gapmax-03.txt AC 51 ms 8152 KiB
05-gapmax-04.txt AC 52 ms 8408 KiB
05-gapmax-05.txt AC 53 ms 8304 KiB
05-gapmax-06.txt AC 53 ms 8236 KiB
05-gapmax-07.txt AC 53 ms 8276 KiB
05-gapmax-08.txt AC 54 ms 8360 KiB
05-gapmax-09.txt AC 52 ms 8320 KiB
05-gapmax-10.txt AC 53 ms 8292 KiB
05-gapmax-11.txt AC 52 ms 8320 KiB
05-gapmax-12.txt AC 55 ms 8284 KiB
05-gapmax-13.txt AC 27 ms 5980 KiB
05-gapmax-14.txt AC 28 ms 6000 KiB
05-gapmax-15.txt AC 26 ms 5928 KiB
05-gapmax-16.txt AC 27 ms 5980 KiB