結果

問題 No.2112 All 2x2 are Equal
ユーザー bayashikobayashiko
提出日時 2022-10-28 18:30:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,710 bytes
コンパイル時間 2,357 ms
コンパイル使用メモリ 210,612 KB
実行使用メモリ 12,812 KB
最終ジャッジ日時 2023-09-20 01:36:20
合計ジャッジ時間 8,866 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#if defined(LOCAL)
#include<stdc++.h>
#else
#include<bits/stdc++.h>
#endif
#include<random>
#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2")
#pragma GCC optimize("unroll-loops")
using namespace std;
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
//#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define MINF (lint)(2e18)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define flc(x) __builtin_popcountll(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
#define all(x) x.begin(),x.end()
//#define vec vector<lint>
#define nep(x) next_permutation(all(x))
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=3e5+5;
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
//vector<int> bucket[MAX_N/1000];
//constexpr int MOD=1000000007;
constexpr int MOD=998244353;
/*#include<atcoder/all>
using namespace atcoder;
typedef __int128_t llint;*/

bool check(vector<vector<int>> A){
    int H=A.size(),W=A[0].size();
    rep(i,H) rep(j,W) A[i][j]--;
    bool apr[H*W]={};
    rep(i,H) rep(j,W){
        if(A[i][j]<0 || A[i][j]>=H*W) return false;
        apr[A[i][j]]=true;
    }
    rep(i,H*W) if(!apr[i]) return false;
    int S=A[0][0]+A[0][1]+A[1][0]+A[1][1];
    rep(i,H-1) rep(j,W-1) if(A[i][j]+A[i+1][j]+A[i][j+1]+A[i+1][j+1]!=S) return false;
    return true;
}

int main(void){
    int H,W;
    cin >> H >> W;
    bool swapped=false;
    if(H%2) swap(H,W),swapped=true;
    vector<vector<int>> A(H,vector<int>(W));
    int lo=1;
    for(int i=0;i<H-1;i+=2){
        rep(j,W){
            A[i][j]=lo;
            A[i+1][j]=H*W+1-lo;
            if(j%2) swap(A[i][j],A[i+1][j]);
            lo++;
        }
    }
    if(H%2){
        rep(j,W){
            if(j==0) A[H-1][j]=lo;
            else A[H-1][j]=2*(H*W+1)-(A[H-1][j-1]+A[H-2][j-1]+A[H-2][j]);
        }
    }
    if(swapped){
        swap(H,W);
        vector<vector<int>> a(H,vector<int>(W));
        rep(i,H) rep(j,W) a[i][j]=A[j][i];
        A=a;
    }
    if(!check(A)) exit(1);
    cout << "Yes" << endl;
    rep(i,H){
        rep(j,W){
            if(i!=H-1 || j!=W-1) cout << A[i][j] << " ";
            else cout << 1 << " ";
        }
        cout << endl;
    }
}
0