結果

問題 No.84 悪の算盤
ユーザー 0w10w1
提出日時 2016-11-28 21:13:29
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,105 bytes
コンパイル時間 1,639 ms
コンパイル使用メモリ 163,980 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-21 10:12:11
合計ジャッジ時間 2,298 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

signed main(){
  int R, C; cin >> R >> C;
  if( not ( R >= C ) )
    swap( R, C );
  ll ans = 0;
  if( ( R & 1 ) and ( C & 1 ) ){
    if( R == C ){
      int st = R - 1;
      int ed = 2;
      ans = 1LL * ( st + ed ) * ( R / 2 ) / 2 + 1; 
    } else{
      int st = R - 2 + C - 2 + 2;
      int ed = ( R - C / 2 * 2 ) - 2 + 1 + 2;
      ans = 1LL * ( st + ed ) * ( C / 2 ) / 2 + ( R + 1 ) / 2;
    }
  } else if( not ( R & 1 ) and not ( C & 1 ) ){
    if( R == C ){
      int st = R - 1;
      int ed = 1;
      ans = 1LL * ( st + ed ) * ( R / 2 ) / 2;
    } else{
      int st = R - 2 + C - 2 + 2;
      int ed = R - C + 2;
      ans = 1LL * ( st + ed ) * ( C / 2 ) / 2; 
    }
  } else{
    if( R & 1 ){
      int st = R - 2 + C - 2 + 2;
      int ed = R - C + 2;
      ans = 1LL * ( st + ed ) * ( C / 2 ) / 2; 
    } else{
      int st = R - 2 + C - 2 + 2;
      int ed = R - ( C / 2 - 1 ) * 2 - 2 + 1 + 2;
      ans = 1LL * ( st + ed ) * ( C / 2 ) / 2 + ( R - C / 2 * 2 ) / 2;
    }
  }
  cout << ans - 1 << endl;
  return 0;
}
  
0