結果

問題 No.180 美しいWhitespace (2)
ユーザー nablaenergy_21nablaenergy_21
提出日時 2015-04-14 14:20:40
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 931 bytes
コンパイル時間 210 ms
コンパイル使用メモリ 27,180 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-17 20:16:14
合計ジャッジ時間 1,505 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <stdio.h>


long long  N;
long long a[1000],b[1000];
long long i,s,t,u,v,ans;

long long min(long long a, long long b){
    if(a>b){return b;}else{return a;}
}

long long max(long long a, long long b){
    if(a>b){return a;}else{return b;}
}

long long ugly(long long x){
    long long mi,ma;

    mi = 1000000000000000000;
    ma = 0;
    
    for(i=0;i<N;i++){
        mi = min(mi, a[i] + b[i] * x);
        ma = max(ma, a[i] + b[i] * x);
    }

    return ma - mi;

}

int main(void){
    scanf("%I64d",&N);
    for(i=0;i<N;i++){
        scanf("%I64d %I64d",&a[i],&b[i]);
    }

    s = 1;
    t = 1000000000;
    while(t-s>2){
        u = (2*s + t)/3;
        v = (s + 2*t)/3;
        if(ugly(u)<=ugly(v)){t = v;}else{s = u;}
    }
    
    if(ugly(s)<=ugly(s+1) && ugly(s)<=ugly(s+2)){
		ans = s;
	}else if(ugly(s+1)<=ugly(s) && ugly(s+1)<=ugly(s+2)){
		ans = s+1;
	}else{
		ans = s+2;
	}
    printf("%I64d\n",ans);
}
0