結果

問題 No.180 美しいWhitespace (2)
ユーザー 158b
提出日時 2015-05-24 12:55:11
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,324 bytes
コンパイル時間 559 ms
コンパイル使用メモリ 65,452 KB
実行使用メモリ 13,888 KB
最終ジャッジ日時 2024-07-06 06:40:34
合計ジャッジ時間 13,415 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 WA * 1
other AC * 4 WA * 2 TLE * 2 -- * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

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


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;
	
	cin >> n;
	for(int i=0; i<n; i++){
		cin >> b[i] >> a[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];
	}
	
	//醜さ計算
	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