結果

問題 No.1851 Regular Tiling
ユーザー yamakeyamake
提出日時 2022-02-25 22:50:43
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 2,694 bytes
コンパイル時間 955 ms
コンパイル使用メモリ 91,800 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-16 18:03:51
合計ジャッジ時間 3,018 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 22 ms
4,380 KB
testcase_02 AC 27 ms
4,376 KB
testcase_03 AC 26 ms
4,376 KB
testcase_04 AC 24 ms
4,380 KB
testcase_05 AC 26 ms
4,376 KB
testcase_06 AC 29 ms
4,376 KB
testcase_07 AC 24 ms
4,380 KB
testcase_08 AC 25 ms
4,376 KB
testcase_09 AC 27 ms
4,376 KB
testcase_10 AC 26 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 48 ms
4,380 KB
testcase_14 AC 81 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/*
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
*/

#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<cstdio>
#include<string>
#include<functional>
#include<set>
#include<array>
#include<map>
#include<stack>
#include<climits>
#include<queue>

 
using namespace std;
#define rep(i,n) for(long long i=0;i<n;++i)
#define rep1(i,n) for(long long i=1;i<=n;++i)
#define rrep(i,n) for(long long i=n-1;i>=0;--i)
#define debug(output) if(debugFlag)cout<<#output<<"= "<<output<<endl
using lint = long long;
typedef pair<int,int> P;
const bool debugFlag=true;
const lint linf=1.1e18;const lint inf=1.01e9;
constexpr int MOD=1000000007;
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(a > b){ a = b; return 1; } return 0; }

void solve(){
    int h,w;cin>>h>>w;
    vector<vector<int>> a(h+5,vector<int>(w+5,-1));
    vector<vector<int>> s={
        {2,2,1},
        {2,2,1},
        {1,1,0}
    };
    rep(i,h/3*3)rep(j,w/3*3){
        a[i+1][j+1]=s[i%3][j%3];
    }
    if(h%3==1){
        if(w%3==1){
            rep(j,w-1)a[0][j+1]=s[2][j%3];
            rep(i,h-1)a[i+1][0]=s[i%3][2];
            a[0][0]=0;
        }
        else if(w%3==2){
            rep(j,w-2)a[0][j+1]=s[2][j%3];
            rep(i,h-1){
                a[i+1][w-1]=s[i%3][0];
                a[i+1][w]=s[i%3][1];
            }
            a[0][w-1]=1;
            a[0][w]=1;
        }
        else rep(j,w)a[0][j+1]=s[2][j%3];
    }
    else if(h%3==2){
        if(w%3==1){
            rep(i,h)a[i+1][0]=s[i%3][2];
            rep(j,w-1){
                a[h-1][j+1]=s[0][j%3];
                a[h][j+1]=s[1][j%3];
            }
        }
        else if(w%3==2){
            rep(i,h){
                a[i+1][w-1]=s[i%3][0];
                a[i+1][w]=s[i%3][1];
            }
            rep(j,w){
                a[h-1][j+1]=s[0][j%3];
                a[h][j+1]=s[1][j%3];
            }
        }
        else{
            rep(j,w){
                a[h-1][j+1]=s[0][j%3];
                a[h][j+1]=s[1][j%3];
            }
        }
    }
    else{
        if(w%3==1)rep(i,h)a[i+1][0]=s[i%3][2];
        else if(w%3==2){
            rep(i,h){
                a[i+1][w-1]=s[i%3][0];
                a[i+1][w]=s[i%3][1];
            }
        }
    }
    rep(i,h+5){
        rep(j,w+5){
            if(a[i][j]==-1)continue;
            cout<<a[i][j]<<" ";
        }
        if(a[i][0]!=-1||a[i][1]!=-1)cout<<endl;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int t;cin>>t;
    rep(i,t)solve();
    return 0;
}
0