답안 #496827

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
496827 2021-12-22T04:58:24 Z Ierus Coin Collecting (JOI19_ho_t4) C++17
0 / 100
1 ms 332 KB
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("unroll-loops,Ofast,O3")
#pragma GCC target("avx,avx2,fma")
#define F first
#define S second
#define sz(x) (int)x.size()
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define int long long
#define NFS ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
typedef long long ll;
const int E = 1e6+777;
const long long inf = 1e18+777;
const int N = 1e6+777;
const int MOD = 1e9+7;
int n;
pair<int,int> edge[N];
priority_queue<tuple<long long,int,int>> pq;
int dist(int x1, int y1, int x2, int y2){
	return abs(x1 - x2) + abs(y1 - y2);
}
bool used1[N], used2[N];
main(){
	cin >> n;
	for(int i = 1; i <= 2 * n; ++i){
		cin >> edge[i].F >> edge[i].S;
	}
	for(int k = 1; k <= 2 * n; ++k){
		int pos = 0;
		for(int i = 1; i <= n; ++i){
			for(int j = 1; j <= 2; ++j){
				++pos;
				pq.push({-dist(edge[k].F,edge[k].S,i,j),k,pos});
			}
		}
	}
	long long res = 0;
	while(!pq.empty()){
		auto[d, pos, pos2] = pq.top();
		pq.pop();
		if(!used1[pos] && !used2[pos2]){
//			cerr << "dist: " << d << " {"<< pos <<"} - " << "{"<<pos2<<"}\n";
			res += -d;
			used1[pos] = true;
			used2[pos2] = true;
		}
	}
	cerr << res;
	cout << res;
}










Compilation message

joi2019_ho_t4.cpp:27:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   27 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Incorrect 1 ms 204 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Incorrect 1 ms 204 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Incorrect 1 ms 204 KB Output isn't correct
7 Halted 0 ms 0 KB -