結果

問題 No.2112 All 2x2 are Equal
ユーザー rogi52rogi52
提出日時 2022-10-28 23:12:33
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 3,057 bytes
コンパイル時間 3,191 ms
コンパイル使用メモリ 213,380 KB
実行使用メモリ 7,228 KB
最終ジャッジ日時 2023-09-20 06:27:23
合計ジャッジ時間 8,921 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 4 ms
4,380 KB
testcase_04 AC 30 ms
5,036 KB
testcase_05 AC 39 ms
5,432 KB
testcase_06 AC 69 ms
6,800 KB
testcase_07 AC 23 ms
4,516 KB
testcase_08 AC 57 ms
6,360 KB
testcase_09 AC 5 ms
4,380 KB
testcase_10 AC 26 ms
4,744 KB
testcase_11 AC 18 ms
4,376 KB
testcase_12 AC 21 ms
4,512 KB
testcase_13 AC 61 ms
6,440 KB
testcase_14 AC 4 ms
4,376 KB
testcase_15 AC 44 ms
5,780 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 54 ms
6,016 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 6 ms
4,380 KB
testcase_20 AC 4 ms
4,380 KB
testcase_21 AC 52 ms
6,040 KB
testcase_22 AC 4 ms
4,376 KB
testcase_23 AC 4 ms
4,376 KB
testcase_24 AC 8 ms
4,380 KB
testcase_25 AC 10 ms
4,380 KB
testcase_26 AC 7 ms
4,380 KB
testcase_27 AC 14 ms
4,380 KB
testcase_28 AC 32 ms
5,200 KB
testcase_29 AC 6 ms
4,380 KB
testcase_30 AC 22 ms
4,436 KB
testcase_31 AC 42 ms
5,608 KB
testcase_32 AC 73 ms
7,228 KB
testcase_33 AC 73 ms
7,048 KB
testcase_34 AC 73 ms
7,192 KB
testcase_35 AC 72 ms
7,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using ld = long double;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int H,W; cin >> H >> W;
    deque<vector<int>> E, O;
    int LL = 1, RR = H * W;
    rep(i,H) {
        vector<int> ans;
        deque<int> L, R;
        if(i % 2 == 0) {
            rep(_,(W+1)/2) L.push_back(LL++);
            rep(_,W/2) R.push_back(RR--);
            int LF = 1, RF = 1;
            while(!L.empty() || !R.empty()) {
                if(!L.empty()) {
                    if(LF) {
                        ans.push_back(L.front());
                        L.pop_front();
                    } else {
                        ans.push_back(L.back());
                        L.pop_back();
                    }
                    LF ^= 1;
                }
                if(!R.empty()) {
                    if(RF) {
                        ans.push_back(R.front());
                        R.pop_front();
                    } else {
                        ans.push_back(R.back());
                        R.pop_back();
                    }
                    RF ^= 1;
                }
            }
            E.push_back(ans);
        } else {
            rep(_,(W+1)/2) R.push_back(RR--);
            rep(_,W/2) L.push_back(LL++);
            int LF = 1, RF = 1;
            while(!L.empty() || !R.empty()) {
                if(!R.empty()) {
                    if(RF) {
                        ans.push_back(R.front());
                        R.pop_front();
                    } else {
                        ans.push_back(R.back());
                        R.pop_back();
                    }
                    RF ^= 1;
                }
                if(!L.empty()) {
                    if(LF) {
                        ans.push_back(L.front());
                        L.pop_front();
                    } else {
                        ans.push_back(L.back());
                        L.pop_back();
                    }
                    LF ^= 1;
                }
            }
            O.push_back(ans);
        }
    }

    vector<vector<int>> ans;
    int EF = 1, OF = 1;
    while(!E.empty() || !O.empty()) {
        if(!E.empty()) {
            if(EF) {
                ans.push_back(E.front());
                E.pop_front();
            } else {
                ans.push_back(E.back());
                E.pop_back();
            }
            EF ^= 1;
        }

        if(!O.empty()) {
            if(OF) {
                ans.push_back(O.front());
                O.pop_front();
            } else {
                ans.push_back(O.back());
                O.pop_back();
            }
            OF ^= 1;
        }
    }

    int S = ans[0][0] + ans[0][1] + ans[1][0] + ans[1][1];
    int ok = 1;
    rep(i,H-1)rep(j,W-1) ok &= ans[i][j] + ans[i+1][j] + ans[i][j+1] + ans[i+1][j+1] == S;
    assert(ok);

    cout << "Yes" << "\n";
    rep(i,H)rep(j,W) cout << ans[i][j] << " \n"[j == W - 1];
}
0