結果

問題 No.540 格子点と経路
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2017-07-01 00:08:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,770 bytes
コンパイル時間 1,672 ms
コンパイル使用メモリ 162,724 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-15 07:18:24
合計ジャッジ時間 2,594 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
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 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 WA -
testcase_10 AC 2 ms
6,940 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 WA -
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/



typedef long long ll;
ll W, H;
//---------------------------------------------------------------------------------------------------
ll solve() {
    if (W == 0 && H == 0) return 0;
    if (W == 1) return 1;
    if (H == 1) return 1;

    if (W % 2 == 1 && H % 2 == 0) {
        ll ans = ((W + 1) / 2) * (H + 1) - W / 2;
        ans += ((W + 1) / 2) * H;
        return ans;
    }
    if (W % 2 == 0 && H % 2 == 1) {
        swap(W, H);
        ll ans = ((W + 1) / 2) * (H + 1) - W / 2;
        ans += ((W + 1) / 2) * H;
        return ans;
    }

    if (W % 2 == 0 && H % 2 == 0) {
        if (W == H) return W * H + 2;
        if (W > H) swap(W, H);
        ll ans = W * (H + 1) + 1;
        return ans;
    }

    return (W + 1) * (H + 1) - 3;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> W >> H;

    cout << solve() << endl;
}
0