답안 #136355

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
136355 2019-07-25T07:41:42 Z 송준혁(#3262) Meandian (CEOI06_meandian) C++14
100 / 100
9 ms 376 KB
#include "libmean.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;

int N;
int Min1, Min2, Max1, Max2;
int ans[110];

int main(){
	int a, b, c;
	N = Init();
	memset(ans, -1, sizeof ans);
	if (N == 4){
		Solution(ans);
		return 0;
	}
	Min1 = 1, Min2 = 2;
	for (int i=3; i+2<=N; i+=3){
		vector<pii> t;
		t.push_back(pii(Meandian(Min2, i, i+1, i+2), Min1));
		t.push_back(pii(Meandian(Min1, i, i+1, i+2), Min2));
		t.push_back(pii(Meandian(Min1, Min2, i+1, i+2), i));
		t.push_back(pii(Meandian(Min1, Min2, i, i+2), i+1));
		t.push_back(pii(Meandian(Min1, Min2, i, i+1), i+2));
		sort(t.begin(), t.end());
		Min1 = t[3].second;
		Min2 = t[4].second;
	}
	if (N % 3 == 0){
		a = N;
		int k;
		for (k=1; k<N; k++){
			if (k != Min1 && k != Min2){
				b = k;
				break;
			}
		}
		for (k++; k<N; k++){
			if (k != Min1 && k != Min2){
				c = k;
				break;
			}
		}
		vector<pii> t;
		t.push_back(pii(Meandian(Min2, a, b, c), Min1));
		t.push_back(pii(Meandian(Min1, a, b, c), Min2));
		t.push_back(pii(Meandian(Min1, Min2, b, c), a));
		t.push_back(pii(Meandian(Min1, Min2, a, c), b));
		t.push_back(pii(Meandian(Min1, Min2, a, b), c));
		sort(t.begin(), t.end());
		Min1 = t[3].second;
		Min2 = t[4].second;
	}
	if (N % 3 == 1){
		a = N, b = N-1;
		int k;
		for (k=1; k<N; k++){
			if (k != Min1 && k != Min2){
				c = k;
				break;
			}
		}
		vector<pii> t;
		t.push_back(pii(Meandian(Min2, a, b, c), Min1));
		t.push_back(pii(Meandian(Min1, a, b, c), Min2));
		t.push_back(pii(Meandian(Min1, Min2, b, c), a));
		t.push_back(pii(Meandian(Min1, Min2, a, c), b));
		t.push_back(pii(Meandian(Min1, Min2, a, b), c));
		sort(t.begin(), t.end());
		Min1 = t[3].second;
		Min2 = t[4].second;
	}

	Max1 = 1, Max2 = 2;
	for (int i=3; i+2<=N; i+=3){
		vector<pii> t;
		t.push_back(pii(Meandian(Max2, i, i+1, i+2), Max1));
		t.push_back(pii(Meandian(Max1, i, i+1, i+2), Max2));
		t.push_back(pii(Meandian(Max1, Max2, i+1, i+2), i));
		t.push_back(pii(Meandian(Max1, Max2, i, i+2), i+1));
		t.push_back(pii(Meandian(Max1, Max2, i, i+1), i+2));
		sort(t.begin(), t.end());
		Max1 = t[0].second;
		Max2 = t[1].second;
	}
	if (N % 3 == 0){
		a = N;
		int k;
		for (k=1; k<N; k++){
			if (k != Max1 && k != Max2){
				b = k;
				break;
			}
		}
		for (k++; k<N; k++){
			if (k != Max1 && k != Max2){
				c = k;
				break;
			}
		}
		vector<pii> t;
		t.push_back(pii(Meandian(Max2, a, b, c), Max1));
		t.push_back(pii(Meandian(Max1, a, b, c), Max2));
		t.push_back(pii(Meandian(Max1, Max2, b, c), a));
		t.push_back(pii(Meandian(Max1, Max2, a, c), b));
		t.push_back(pii(Meandian(Max1, Max2, a, b), c));
		sort(t.begin(), t.end());
		Max1 = t[0].second;
		Max2 = t[1].second;
	}
	if (N % 3 == 1){
		a = N, b = N-1;
		int k;
		for (k=1; k<N; k++){
			if (k != Max1 && k != Max2){
				c = k;
				break;
			}
		}
		vector<pii> t;
		t.push_back(pii(Meandian(Max2, a, b, c), Max1));
		t.push_back(pii(Meandian(Max1, a, b, c), Max2));
		t.push_back(pii(Meandian(Max1, Max2, b, c), a));
		t.push_back(pii(Meandian(Max1, Max2, a, c), b));
		t.push_back(pii(Meandian(Max1, Max2, a, b), c));
		sort(t.begin(), t.end());
		Max1 = t[0].second;
		Max2 = t[1].second;
	}

	int r1 = Meandian(Min1, Min2, Max1, Max2);
	for (int i=1; i<=N; i++) if (i != Min1 && i != Min2 && i != Max1 && i != Max2) {
		int r2 = Meandian(Min1, Min2, i, Max2);
		int r3 = Meandian(Min1, i, Max1, Max2);
		ans[i-1] = r2+r3-r1;
	}
	Solution(ans);
	return 0;
}

Compilation message

meandian.cpp: In function 'int main()':
meandian.cpp:123:27: warning: 'c' may be used uninitialized in this function [-Wmaybe-uninitialized]
   t.push_back(pii(Meandian(Max2, a, b, c), Max1));
                   ~~~~~~~~^~~~~~~~~~~~~~~
meandian.cpp:108:27: warning: 'b' may be used uninitialized in this function [-Wmaybe-uninitialized]
   t.push_back(pii(Meandian(Max1, Max2, a, b), c));
                   ~~~~~~~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 248 KB Output is correct
3 Correct 3 ms 248 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 3 ms 248 KB Output is correct
6 Correct 4 ms 248 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 9 ms 248 KB Output is correct
9 Correct 7 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct