結果

問題 No.2112 All 2x2 are Equal
ユーザー bayashikobayashiko
提出日時 2022-10-05 02:03:07
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 88 ms / 2,000 ms
コード長 2,631 bytes
コンパイル時間 3,323 ms
コンパイル使用メモリ 210,428 KB
実行使用メモリ 12,832 KB
最終ジャッジ日時 2023-08-30 07:16:27
合計ジャッジ時間 8,303 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 4 ms
4,376 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 37 ms
8,264 KB
testcase_05 AC 45 ms
7,744 KB
testcase_06 AC 78 ms
11,180 KB
testcase_07 AC 27 ms
6,164 KB
testcase_08 AC 68 ms
12,832 KB
testcase_09 AC 5 ms
4,380 KB
testcase_10 AC 29 ms
5,888 KB
testcase_11 AC 22 ms
5,928 KB
testcase_12 AC 26 ms
6,552 KB
testcase_13 AC 70 ms
10,500 KB
testcase_14 AC 5 ms
4,376 KB
testcase_15 AC 53 ms
9,132 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 65 ms
9,668 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 7 ms
4,380 KB
testcase_20 AC 3 ms
4,384 KB
testcase_21 AC 62 ms
9,856 KB
testcase_22 AC 5 ms
4,380 KB
testcase_23 AC 4 ms
4,380 KB
testcase_24 AC 8 ms
4,380 KB
testcase_25 AC 11 ms
4,376 KB
testcase_26 AC 8 ms
4,380 KB
testcase_27 AC 17 ms
5,440 KB
testcase_28 AC 40 ms
8,668 KB
testcase_29 AC 7 ms
4,376 KB
testcase_30 AC 27 ms
6,432 KB
testcase_31 AC 50 ms
10,188 KB
testcase_32 AC 84 ms
11,968 KB
testcase_33 AC 83 ms
12,032 KB
testcase_34 AC 88 ms
11,960 KB
testcase_35 AC 88 ms
12,128 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] << " ";
        cout << endl;
    }
}
0