답안 #497914

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
497914 2021-12-24T04:41:27 Z Nuraly_Serikbay Coin Collecting (JOI19_ho_t4) C++14
0 / 100
1 ms 332 KB
#include <bits/stdc++.h>
  
#define endl "\n"
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define sz size()
#define rep(i,k,n) for(int i = k ; i <= n ; ++i)
#define per(i,k,n) for(int i = k ; i >= n ; --i)
#define Zymraq() ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define all(x) x.begin(),x.end()
#define fr(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
#define toqta return 0
#define PERMUTE next_permutation
#define no cout<<"No"<<endl;
#define yes cout<<"Yes"<<endl;
#define a() a + 1, a + n + 1  

using namespace std;
 
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse,-fgcse-lm")
#pragma GCC optimize("-ftree-pre,-ftree-vrp")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")

   
typedef long long ll;
typedef unsigned long long ull;
typedef string S;
typedef double ld;
typedef long double lld;
  
const int N = 1e6 + 17;
const int modd = 1e9 + 7;
const ll INF = 1e18 - 19;
const int P = 37;
const ll NN = 1e7 + 17;
const ld eps = 1e-19;
const double pi = 3.141592653589793238462643383279 ;
   
 
bool sortbysec(const pair<int,int> &a, const pair<int,int> &b){
    return (a.second < b.second);
}
 
void pre (ll a) {
    cout << fixed << setprecision(a);
    return;
}

ll n, x[N], y[N];
ll in[200][200];
ll totalans;


inline void Solution () {
	cin >> n;
	for (int i = 1; i <= 2 * n; ++ i) {
		cin >> x[i] >> y[i];
	}
	for (ll i = 1; i <= 2 * n; ++ i) {
		ll mn = INF, xx, yy;
		for (ll j = 1; j <= n; ++ j) {
			if (mn > abs(x[i] - j) + abs(y[i] - 2)) {
				mn = abs(x[i] - j) + abs(y[i] - 2);
				xx = j, yy = 2;	
			}
			if (mn > abs(x[i] - j) + abs(y[i] - 1)) {
				mn = abs(x[i] - j) + abs(y[i] - 1);
				xx = j, yy = 1;
			}
		}
		in[xx][yy] ++;
		totalans += mn;
	}
	for (int i = 1; i <= n; ++ i) {
		for (int j = 1; j <= 2; ++ j) {
			if (in[i][j] == 0) {
				ll mn = INF, xx, yy;
				for (int k = 1; k <= n; ++ k) {
					if (in[k][1] > 1 && mn > abs (i - k) + abs (j - 1)) {
						mn = abs (i - k) + abs (j - 1);
						xx = k, yy = 1;
					}
					if (in[k][2] > 1 && mn > abs (i - k) + abs (j - 2)) {
						mn = abs (i - k) + abs (j - 2);
						xx = k, yy = 2;
					}
					
				}
				if (mn == INF) continue;
				in[xx][yy] --;
				in[i][j] = 1;
				totalans += mn; 
			}
		}
	}
	cout << totalans;
	return;
}    
 
 
int main () {
	Zymraq();
	Solution ();
	exit (0);
}

Compilation message

joi2019_ho_t4.cpp: In function 'void Solution()':
joi2019_ho_t4.cpp:80:12: warning: 'yy' may be used uninitialized in this function [-Wmaybe-uninitialized]
   80 |   in[xx][yy] ++;
      |   ~~~~~~~~~^
joi2019_ho_t4.cpp:80:12: warning: 'xx' may be used uninitialized in this function [-Wmaybe-uninitialized]
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 0 ms 324 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Incorrect 0 ms 332 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 0 ms 324 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Incorrect 0 ms 332 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 0 ms 324 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Incorrect 0 ms 332 KB Output isn't correct
7 Halted 0 ms 0 KB -