結果

問題 No.180 美しいWhitespace (2)
ユーザー nablaenergy_21
提出日時 2015-04-14 14:19:38
言語 C90
(gcc 12.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 925 bytes
コンパイル時間 677 ms
コンパイル使用メモリ 21,760 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-04 14:28:39
合計ジャッジ時間 1,600 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 31
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:31:16: warning: format ‘%d’ expects argument of type ‘int *’, but argument 2 has type ‘long long int *’ [-Wformat=]
   31 |     scanf("%I64d",&N);
      |            ~~~~^  ~~
      |                |  |
      |                |  long long int *
      |                int *
      |            %I64lld
main.c:33:20: warning: format ‘%d’ expects argument of type ‘int *’, but argument 2 has type ‘long long int *’ [-Wformat=]
   33 |         scanf("%I64d %I64d",&a[i],&b[i]);
      |                ~~~~^        ~~~~~
      |                    |        |
      |                    int *    long long int *
      |                %I64lld
main.c:33:26: warning: format ‘%d’ expects argument of type ‘int *’, but argument 3 has type ‘long long int *’ [-Wformat=]
   33 |         scanf("%I64d %I64d",&a[i],&b[i]);
      |                      ~~~~^        ~~~~~
      |                          |        |
      |                          int *    long long int *
      |                      %I64lld
main.c:47:17: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long long int’ [-Wformat=]
   47 |     printf("%I64d\n",ans);
      |             ~~~~^    ~~~
      |                 |    |
      |                 int  long long int
      |             %I64lld
main.c:31:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   31 |     scanf("%I64d",&N);
      |     ^~~~~~~~~~~~~~~~~
main.c:33:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   33 |         scanf("%I64d %I64d",&a[i],&b[i]);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

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