結果

問題 No.180 美しいWhitespace (2)
ユーザー 158b158b
提出日時 2015-05-24 13:19:14
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,370 bytes
コンパイル時間 526 ms
コンパイル使用メモリ 67,536 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-20 11:14:11
合計ジャッジ時間 8,239 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 WA -
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 5 ms
4,380 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <limits.h>
#include <vector>
#include <numeric>
using namespace std;

	int n_kari;
	long b_kari[1000];
	long a_kari[1000];
	
//デフォルト昇順
void combsort(){
	bool flg;
	int h;
	
	h = n_kari / 1.3;
	while(true){
		flg = true;
		
		for(int i=0; i+h<n_kari; i++){
			if(b_kari[i] > b_kari[i+h]){		//ソート基準変更位置
				//swap
				swap(a_kari[i], a_kari[i+h]);
				swap(b_kari[i], b_kari[i+h]);
				
				flg = false;
			}
		}
		
		if(h == 1){
			if(flg){
				break;
			}
		}else{
			h /= 1.3;
		}
	}
}


	
int main(){

	int n;
	//y=ax+b

	long b[1000];	//スペース
	long a[1000];	//タブ
	long y[1000];	//相対位置
	long x;
	long ansx,ansy;
	int maxno,minno;
	int targetmax = 0;	//該当の最初の位置
	int targetmin = 0;	//該当の最初の位置
	long temp;
	long a_min = LONG_MAX;
	long a_max = 0;
	bool flg;
	
	cin >> n_kari;
	for(int i=0; i<n_kari; i++){
		cin >> b_kari[i] >> a_kari[i];
	}
	
	//ソート
	combsort();
	
	//本データ作成
	a[0] = a_kari[0];
	b[0] = b_kari[0];
	a[1] = a_kari[n_kari-1];
	b[1] = b_kari[n_kari-1];
	n = 2;
	for(int i=1; i<n_kari-1; i++){
		flg = false;
		if(a_kari[i] > a_max){
			a_max = a_kari[i];
			flg = true;
		}
		if(a_kari[i] < a_min){
			a_max = a_kari[i];
			flg = true;
		}
		
		if(flg){
			a[n] = a_kari[i];
			b[n] = b_kari[i];
			n ++;
		}
	}
	
	//targetmax,targetmin計算
	for(int i=0; i<n; i++){
		if(a_kari[i] > a_kari[targetmax] || a_kari[i] == a_kari[targetmax] && b_kari[i] > b_kari[targetmax]){
			targetmax = i;
		}
		if(a_kari[i] < a_kari[targetmin] || a_kari[i] == a_kari[targetmin] && b_kari[i] < b_kari[targetmax]){
			targetmin = i;
		}
	}
	
	//相対位置計算
	for(int i=0; i<n; i++){
		y[i] = b[i] - b[targetmax];
	}
	
	//醜さ計算
	maxno = max_element(y, y + n) - y;
	minno = min_element(y, y + n) - y;
	ansx = 0;
	ansy = *(maxno + y) - *(minno + y);
	
	x = 0;
	while(maxno != targetmax && minno != targetmin){
		//タブ幅を進める
		x ++;
		
		//相対位置計算
		for(int i=0; i<n; i++){
			y[i] += a[i] - a[targetmax];
		}
		
		//醜さ計算
		maxno = max_element(y, y + n) - y;
		minno = min_element(y, y + n) - y;
		temp = *(maxno + y) - *(minno + y);
		
		//ans更新
		if(temp < ansy){
			ansy = temp;
			ansx = x;
		}
	}
	
	cout << ansx << endl;
	return 0;
}
0