結果

問題 No.180 美しいWhitespace (2)
ユーザー 158b158b
提出日時 2015-05-24 15:42:20
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 2,299 bytes
コンパイル時間 444 ms
コンパイル使用メモリ 67,192 KB
実行使用メモリ 7,536 KB
最終ジャッジ日時 2023-09-20 11:21:17
合計ジャッジ時間 9,609 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 9 ms
4,376 KB
testcase_04 AC 661 ms
4,380 KB
testcase_05 AC 133 ms
4,380 KB
testcase_06 AC 510 ms
4,376 KB
testcase_07 AC 293 ms
4,376 KB
testcase_08 AC 820 ms
4,380 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 TLE -
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 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:113:36: warning: ‘minno’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  while(maxno != targetmax && minno != targetmin){
                              ~~~~~~^~~~~~~~~~~~
main.cpp:113:14: warning: ‘maxno’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  while(maxno != targetmax && minno != targetmin){
        ~~~~~~^~~~~~~~~~~~

ソースコード

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 = -1;
	
	cin >> n_kari;
	for(int i=0; i<n_kari; i++){
		cin >> b_kari[i] >> a_kari[i];
	}
	
	//ソート
	combsort();
	
	//本データ作成
	n = 0;
	for(int i=0; i<n_kari-1; i++){
		if(a_kari[i] < a_min){
			a_min = a_kari[i];
			
			a[n] = a_kari[i];
			b[n] = b_kari[i];
			//cout << n << ":" << a[n] << "\t" << b[n] << endl;
			n ++;
		}
	}
	//cout << "---" << endl;
	for(int i=n_kari-1; i>=1; i--){
		if(a_kari[i] > a_max){
			a_max = a_kari[i];
			
			a[n] = a_kari[i];
			b[n] = b_kari[i];
			//cout << n << ":" << a[n] << "\t" << b[n] << endl;
			n ++;
		}
	}
	//targetmax,targetmin計算
	for(int i=0; i<n; i++){
		if(a[i] > a[targetmax] || a[i] == a[targetmax] && b[i] > b[targetmax]){
			targetmax = i;
		}
		if(a[i] < a[targetmin] || a[i] == a[targetmin] && b[i] < b[targetmax]){
			targetmin = i;
		}
	}
	
	//相対位置計算
	for(int i=0; i<n; i++){
		y[i] = b[i] - b[targetmax];
	}
	
	//醜さ計算
	ansy = LONG_MAX;
	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;
		}else{
			break;
		}
	}
	
	
	cout << ansx << endl;
	
	return 0;
}
0