結果

問題 No.178 美しいWhitespace (1)
ユーザー Bantako
提出日時 2017-07-02 19:28:26
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 652 bytes
コンパイル時間 229 ms
コンパイル使用メモリ 22,784 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-05 08:43:34
合計ジャッジ時間 830 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 21
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:2:1: warning: ISO C++ forbids declaration of ‘main’ with no type [-Wreturn-type]
    2 | main(){
      | ^~~~
main.cpp: In function ‘int main()’:
main.cpp:4:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    4 |     scanf("%d",&N);
      |     ~~~~~^~~~~~~~~
main.cpp:6:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    6 |     scanf("%d %d",&A,&B);
      |     ~~~~~^~~~~~~~~~~~~~~
main.cpp:11:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   11 |         scanf("%d %d",&A,&B);
      |         ~~~~~^~~~~~~~~~~~~~~

ソースコード

diff #

#include<stdio.h>
main(){
    int N;
    scanf("%d",&N);
    int A,B;
    scanf("%d %d",&A,&B);
    int isodd = A%2;//奇数かどうかのフラグ
    int max = A + 4*B;
    long long count = 0;
    for(int i=1;i < N;i++){
        scanf("%d %d",&A,&B);
        //もし偶奇が一致しなかったら
        if(isodd != A%2){
            printf("-1\n");
            return 0;
        }
        if(max < A + 4*B){//最大値更新
            count += (A + 4*B - max)/2 * i;//現最大値と前最大値の差*行数
            max = A + 4*B;
        }else{
            count += (max - (A+4*B)) / 2;
        }
    }
    printf("%lld\n",count);
}
0