답안 #1100268

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1100268 2024-10-13T11:12:00 Z vjudge1 Coin Collecting (JOI19_ho_t4) C++17
0 / 100
1000 ms 4608 KB
//UNSTOPPABLE
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define int long long
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define pii pair<int,int>
#define tpii pair <pair <int,int> , int>
#define bruh cout << "NO\n"
using namespace std;
using namespace __gnu_pbds;
const int N = 3e5 + 5;
int mod = 1e9 + 7;
const int INF = 1e18;
int n,a[N],b[N],dp[2001][2001],d[2001][2001],p[N];
pii val[2001];
int dist(int a , int b , int c , int d){
	return abs(a - c) + abs(b - d);
}
void Goldik(){
	cin >> n;
	for(int i = 1 ; i <= n * 2 ; i++){
		cin >> a[i] >> b[i];
		p[i] = i;
	}
	int cur = 0;
	for(int i = 1 ; i <= 2 ; i++){
		for(int j = 1 ; j <= n ; j++){
			val[++cur] = {j , i};
		}
	}
	int ans = INF;
	do{
		int ans1 = 0;
		for(int i = 1 ; i <= n * 2 ; i++){
			ans1 += dist(a[i] , b[i] , val[p[i]].F , val[p[i]].S);
		}
		ans = min(ans , ans1);
	}while(next_permutation(p + 1 , p + n * 2 + 1));
	cout << ans;
}
//rewai mnogo zadach vozmozhno odna iz nih gde to popadetsya
//returning winter prime?
//chem prowe tem luchshe
signed main(/*AZ AZDAN UZDIKSIZ*/){
	//freopen("txt.in","r",stdin);
	//freopen("txt.out","w",stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	srand(time(0));
	int TT = 1;
	// cin >> TT;
	for(int i = 1 ; i <= TT ; i++){
		//cout << "Case " << i << ": ";
		Goldik();
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 1 ms 4432 KB Output is correct
4 Execution timed out 1050 ms 4608 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 1 ms 4432 KB Output is correct
4 Execution timed out 1050 ms 4608 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 1 ms 4432 KB Output is correct
4 Execution timed out 1050 ms 4608 KB Time limit exceeded
5 Halted 0 ms 0 KB -