結果
| 問題 |
No.1974 2x2 Flipper
|
| コンテスト | |
| ユーザー |
suzuken_w
|
| 提出日時 | 2022-06-10 22:55:52 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 82 ms / 2,000 ms |
| コード長 | 2,360 bytes |
| コンパイル時間 | 2,696 ms |
| コンパイル使用メモリ | 217,928 KB |
| 最終ジャッジ日時 | 2025-01-29 20:12:54 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 25 |
ソースコード
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>;
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=998244353;
// const ll mod=1000000007;
const vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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; }
template<class T>void debag(const vector<T> &a){cerr<<"debag :";for(auto v:a)cerr<<v<<" ";cerr<<"\n";}
template<class T>void print(const vector<T> &a){for(auto v:a)cout<<v<<" ";cout<<"\n";}
int main(){
int h,w;
cin>>h>>w;
if(h==1||w==1){
cout<<0<<"\n";
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
cout<<0<<(j==w-1?"\n":" ");
}
}
return 0;
}
if(h%2==0&&w%2==0){
cout<<h*w<<"\n";
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
cout<<1<<(j==w-1?"\n":" ");
}
}
return 0;
}
if(h%2==1&&w%2==1){
V<V<int>> res(h,V<int>(w,1));
for(int i=0;i<min(h,w);i++){
res[h-1-i][w-1-i]=0;
if(h-1-i==0){
for(int j=w-1-i;j>=0;j--){
res[0][j]=0;
}
break;
}
if(w-1-i==0){
for(int j=h-1-i;j>=0;j--){
res[j][0]=0;
}
break;
}
}
int ans=0;
for(int i=0;i<h;i++)for(int j=0;j<w;j++)ans+=res[i][j];
cout<<ans<<"\n";
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
cout<<res[i][j]<<(j==w-1?"\n":" ");
}
}
return 0;
}
V<V<int>> res(h,V<int>(w,1));
int ans=h*w;
if(h%2==1){
for(int i=0;i<w;i++)res[h-1][i]=0;
ans-=w;
}else{
for(int i=0;i<h;i++){
res[i][w-1]=0;
}
ans-=h;
}
cout<<ans<<"\n";
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
cout<<res[i][j]<<(j==w-1?"\n":" ");
}
}
}
suzuken_w