結果

問題 No.1974 2x2 Flipper
ユーザー umezo
提出日時 2022-06-10 23:03:04
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 80 ms / 2,000 ms
コード長 998 bytes
コンパイル時間 1,980 ms
コンパイル使用メモリ 197,316 KB
最終ジャッジ日時 2025-01-29 20:14:22
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
 
#include<bits/stdc++.h>
using namespace std;
 
int G[1010][1010];

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  int h,w;
  cin>>h>>w;
  
  if(h%2==0 && w%2==0){
    rep(i,h) rep(j,w) G[i][j]=1;
  }
  else if(h%2==0){
    rep(i,h) rep(j,w-1) G[i][j]=1;
  }
  else if(w%2==0){
    rep(i,h-1) rep(j,w) G[i][j]=1;
  }
  else{
    auto dfs=[&](auto dfs,int x,int y,int rx,int ry){
      if(rx==1 || ry==1) return;
      G[x][y]=1,G[x+1][y+1]=1;
      for(int j=0;j<ry-2;j++){
        G[x][y+2+j]=1;
        G[x+1][y+2+j]=1;
      }
      for(int i=0;i<rx-2;i++){
        G[x+2+i][y]=1;
        G[x+2+i][y+1]=1;
      }
      dfs(dfs,x+2,y+2,rx-2,ry-2);
    };
    dfs(dfs,0,0,h,w);
  }
  
  int ans=0;
  rep(i,h) rep(j,w) if(G[i][j]) ans++;
  cout<<ans<<endl;
  
  rep(i,h){
    rep(j,w){
      if(j) cout<<" ";
      cout<<G[i][j];
    }
    cout<<endl;
  }

  return 0;
}
0