結果

問題 No.2112 All 2x2 are Equal
ユーザー bayashikobayashiko
提出日時 2022-10-05 02:19:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 2,692 bytes
コンパイル時間 2,308 ms
コンパイル使用メモリ 210,876 KB
実行使用メモリ 12,712 KB
最終ジャッジ日時 2023-08-30 07:16:15
合計ジャッジ時間 10,520 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 4 ms
4,376 KB
testcase_03 AC 4 ms
4,376 KB
testcase_04 AC 36 ms
8,272 KB
testcase_05 AC 45 ms
7,728 KB
testcase_06 AC 77 ms
11,448 KB
testcase_07 AC 27 ms
6,200 KB
testcase_08 AC 68 ms
12,712 KB
testcase_09 AC 5 ms
4,384 KB
testcase_10 AC 29 ms
6,172 KB
testcase_11 AC 22 ms
5,924 KB
testcase_12 AC 25 ms
6,480 KB
testcase_13 AC 69 ms
10,448 KB
testcase_14 AC 5 ms
4,380 KB
testcase_15 AC 52 ms
9,032 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 64 ms
9,716 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 6 ms
4,376 KB
testcase_20 AC 4 ms
4,380 KB
testcase_21 AC 62 ms
9,608 KB
testcase_22 AC 4 ms
4,376 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 8 ms
4,376 KB
testcase_25 AC 10 ms
4,380 KB
testcase_26 AC 8 ms
4,376 KB
testcase_27 AC 17 ms
5,340 KB
testcase_28 AC 39 ms
8,524 KB
testcase_29 AC 7 ms
4,376 KB
testcase_30 AC 27 ms
6,468 KB
testcase_31 AC 52 ms
10,340 KB
testcase_32 AC 83 ms
11,956 KB
testcase_33 AC 82 ms
11,940 KB
testcase_34 AC 89 ms
11,924 KB
testcase_35 AC 88 ms
12,020 KB
権限があれば一括ダウンロードができます

ソースコード

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){
            cout << A[i][j];
            if(j!=W-1) cout << " ";
            else cout << endl;
        }
    }
}
0