結果
| 問題 | 
                            No.837 Noelちゃんと星々2
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2019-06-14 22:32:52 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,351 bytes | 
| コンパイル時間 | 946 ms | 
| コンパイル使用メモリ | 87,736 KB | 
| 実行使用メモリ | 6,820 KB | 
| 最終ジャッジ日時 | 2024-11-14 06:59:39 | 
| 合計ジャッジ時間 | 2,910 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 20 WA * 9 | 
ソースコード
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>
ll n, ans = INF, ck = -1;
bool ok = true;
int main() {
	cin >> n;
	vector<ll> s(n), t(n);
	REP(i, n) {
		cin >> s[i];
		t[i] = s[i];
	}
	if (n == 2) {
		if (s[0] == s[1])cout << 1 << endl;
		else cout << 0 << endl;
		return 0;
	}
	sort(ALL(t));
	t.erase(unique(ALL(t)), t.end());
	REP(i, n) {
		if (ck == -1)ck = s[i];
		else if (ck != s[i]) ok = false;
	}
	ll b = t.size() / 3;
	if (ok) {
		cout << 1 << endl;
		return 0;
	}
	FOR(x, b - 10, b + 10) {
		FOR(y, (ll)t.size() - b - 10, (ll)t.size() - b + 10) {
			//cout << x << y << endl;
			if (x < y and x >= 0 and y < t.size()) {
				ll now = 0;
				REP(i, n) {
					now += min(abs(s[i] - t[x]), abs(s[i] - t[y]));
				}
				ans = min(ans, now);
			}
		}
	}
	cout << ans << endl;
}