結果

問題 No.84 悪の算盤
ユーザー 0w1
提出日時 2016-11-28 21:13:29
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,105 bytes
コンパイル時間 1,510 ms
コンパイル使用メモリ 167,080 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-13 08:59:14
合計ジャッジ時間 1,929 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

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