| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1308937 | wangzhiyi33 | Coin Collecting (JOI19_ho_t4) | C++20 | 34 ms | 2784 KiB |
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fir first
#define sec second
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int n;
cin>>n;
int cnt[n+1][3]; memset(cnt,0,sizeof cnt);
int ans=0;
for(int q=1;q<=2*n;q++){
int x,y; cin>>x>>y;
int barux=x,baruy=y;
if(y<=1){
if(x<1){
barux=1;
}
else if(x>n){
barux=n;
}
baruy=1;
}
else{
if(x<1){
barux=1;
}
else if(x>n){
barux=n;
}
baruy=2;
}
ans+=abs(x-barux)+abs(y-baruy);
cnt[barux][baruy]++;
}
int up=0,down=0;
for(int q=1;q<=n;q++){
up+=(cnt[q][1]-1); down+=(cnt[q][2]-1);
if(up>0 && down<0){
int brp=min(up,-down);
up-=brp; down+=brp;
ans+=brp;
}
if(down>0 && up<0){
int brp=min(-up,down);
up+=brp; down-=brp;
ans+=brp;
}
ans+=abs(up)+abs(down);
}
cout<<ans<<endl;
}| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
