답안 #895703

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
895703 2023-12-30T14:59:03 Z beepbeepsheep Coin Collecting (JOI19_ho_t4) C++17
0 / 100
1 ms 604 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef tree<long long, null_type, less_equal<>,
        rb_tree_tag, tree_order_statistics_node_update>
        ordered_set;
#define ll long long
#define ii pair<ll,ll>

#ifndef DEBUG
#define cerr if (0) cerr
#define endl '\n'
#endif

const ll inf=1e15;
const ll maxn=1e5+5;
const ll mod=1e9+7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define int long long
ll arr[maxn][3];
signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll n,x,y,ans=0;
	cin>>n;
	for (int i=1;i<=2*n;i++){
		cin>>x>>y;
		if (x<=1 && y<=1) arr[1][1]++, ans+=abs(1-x)+abs(1-y);
		if (1<x && x<n && y<=1) arr[x][1]++, ans+=abs(1-y);
		if (x>=n && y<=1) arr[n][1]++, ans+=abs(n-x)+abs(1-y);
		if (x<=1 && y>=2) arr[1][2]++, ans+=abs(1-x)+abs(2-y);
		if (1<x && x<n && y>=2) arr[x][2]++, ans+=abs(2-y);
		if (x>=n && y>=2) arr[n][2]++, ans+=abs(n-x)+abs(2-y);
	}
	ll tot=0;
	for (int i=1;i<=2;i++){
		for (int j=1;j<=n;j++) cerr<<arr[j][i]<<' ';
		cerr<<endl;
	}
	for (int i=1;i<=n;i++){
		tot+=arr[i][1]+arr[i][2];
		ans+=abs(tot-2*i);
	}
	assert(tot==2*n);
	tot=0;
	for (int i=1;i<=n;i++){
		tot+=arr[i][1];
	}
	ans+=abs(n-tot);
	cout<<ans;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -