제출 #1149372

#제출 시각아이디문제언어결과실행 시간메모리
1149372KluydQCoin Collecting (JOI19_ho_t4)C++20
0 / 100
0 ms320 KiB
#include <bits/stdc++.h>
 
#define respagold ios_base::sync_with_stdio(0), cin.tie(0);
#define ll long long
#define int long long
#define int2 __int128_t
#define FOR( i, x, n, d ) for( int i = x; i <= n; i += d )
#define FORR( i, x, n, d ) for( int i = x; i >= n; i -= d )
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x.size())
#define pb push_back
#define ins insert
#define lb lower_bound
#define ub upper_bound
#define pii pair <int, int>
#define mkp make_pair
 
using namespace std;
 
const int N = 1e5 + 123;
const int inf = 1e18;
const int MOD1 = 1e9 + 7;
const int MOD = 998244353;
const int P = 6547;
 
int a[N], b[N], x[N], n, m, k, q, y, z;
string s; int dp[501][501][501], ans;
pii bob[10];
 
mt19937 rng( chrono::steady_clock::now().time_since_epoch().count());
 
int rand( int l, int r )
{
    uniform_int_distribution <int> uid( l, r );
    return uid( rng );
}
void solve()
{
	cin >> n;
	vector <int> v;
	FOR( i, 1, 2 * n, 1 ) cin >> a[i] >> b[i], v.pb(i);
	
	bob[1] = { 1, 1 }; bob[2] = { 2, 1 }; bob[3] = { 3, 1 };
	bob[4] = { 1, 2 }; bob[5] = { 2, 2 }; bob[6] = { 3, 2 };
	
	ans = inf;
	
	do
	{
		int res = 0;
		FOR( i, 0, sz(v) - 1, 1 ) res += abs( bob[i + 1].F - a[v[i]] ) + abs( bob[i + 1].S - b[v[i]] );
		ans = min( ans, res );
	} while( next_permutation( all( v ) ));
	
	cout << ans;
}
signed main() 
{
//	freopen("connect.in", "r", stdin);
//	freopen("connect.out", "w", stdout);
	    
    respagold
    
    int test = 1;
    
    if( !test ) cin >> test;
	
	while( test -- )
	{
		solve();
	}
}
// solved by KluydQ  
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...