제출 #478554

#제출 시각아이디문제언어결과실행 시간메모리
478554MonkeyKingCoin Collecting (JOI19_ho_t4)C++14
100 / 100
51 ms4808 KiB
#include <numeric>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <stack>
#include <assert.h>
#include <bitset>
#include <time.h>
#define Endl endl
#define mp make_pair
#define mt make_tuple
#define ll long long 
#define ull unsigned long long
#define pii pair<int,int>
#define over(A) {cout<<A<<endl;exit(0);}
#define all(A) A.begin(),A.end()
#define quickcin ios_base::sync_with_stdio(false);
const int mod=1000000007;
const int gmod=3;
const int inf=1039074182;
const double eps=1e-9;
const double pi=3.141592653589793238462643383279;
const ll llinf=2LL*inf*inf;
template <typename T1,typename T2> inline void chmin(T1 &x,T2 b) {if(b<x) x=b;}
template <typename T1,typename T2> inline void chmax(T1 &x,T2 b) {if(b>x) x=b;}
inline void chadd(int &x,int b) {x+=b-mod;x+=(x>>31 & mod);}
template <typename T1,typename T2> inline void chadd(T1 &x,T2 b) {x+=b;if(x>=mod) x-=mod;}
template <typename T1,typename T2> inline void chmul(T1 &x,T2 b) {x=1LL*x*b%mod;}
template <typename T1,typename T2> inline void chmod(T1 &x,T2 b) {x%=b,x+=b;if(x>=b) x-=b;}
template <typename T> inline T mabs(T x) {return (x<0?-x:x);}
using namespace std;
int n;
typedef pair<ll,ll> pll;
vector<pll> U,D;
int t[4];

ll calc(pll x,pll y)
{
	return mabs(x.first-y.first)+mabs((ll)x.second-y.second);
}

int cnt[100005][3];
ll res;
int main()
{
	// freopen("c.in"	,"r",stdin);
	// freopen("c.out","w",stdout);
	cin>>n;
	for(int i=0;i<n*2;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		ll nx=min(max(x,1),n),ny=min(max(y,1),2);
		res+=mabs(nx-x)+mabs(ny-y);
		cnt[(int)nx][(int)ny]++;
	}
	for(int i=1;i<=n;i++)
	{
		cnt[i][1]--;cnt[i][2]--;
		if(1LL*cnt[i][1]*cnt[i][2]<0)
		{
			int tr=min(mabs(cnt[i][1]),mabs(cnt[i][2]));
			if(cnt[i][1]<0) cnt[i][1]+=tr;else cnt[i][1]-=tr;
			if(cnt[i][2]<0) cnt[i][2]+=tr;else cnt[i][2]-=tr;
			res+=tr;
		}
		cnt[i+1][1]+=cnt[i][1];
		cnt[i+1][2]+=cnt[i][2];
		res+=mabs(cnt[i][1])+mabs(cnt[i][2]);
	}
	cout<<res<<endl;
	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:60:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |   scanf("%d%d",&x,&y);
      |   ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...