結果

問題 No.1974 2x2 Flipper
ユーザー suzuken_wsuzuken_w
提出日時 2022-06-10 22:55:52
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 66 ms / 2,000 ms
コード長 2,360 bytes
コンパイル時間 5,270 ms
コンパイル使用メモリ 217,960 KB
実行使用メモリ 7,188 KB
最終ジャッジ日時 2023-10-21 06:00:40
合計ジャッジ時間 6,613 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 8 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 40 ms
4,348 KB
testcase_04 AC 20 ms
4,548 KB
testcase_05 AC 13 ms
4,348 KB
testcase_06 AC 28 ms
4,348 KB
testcase_07 AC 22 ms
4,548 KB
testcase_08 AC 5 ms
4,348 KB
testcase_09 AC 34 ms
5,076 KB
testcase_10 AC 5 ms
4,348 KB
testcase_11 AC 25 ms
4,812 KB
testcase_12 AC 40 ms
5,868 KB
testcase_13 AC 26 ms
4,812 KB
testcase_14 AC 16 ms
4,348 KB
testcase_15 AC 47 ms
6,396 KB
testcase_16 AC 5 ms
4,348 KB
testcase_17 AC 35 ms
4,348 KB
testcase_18 AC 5 ms
4,348 KB
testcase_19 AC 6 ms
4,348 KB
testcase_20 AC 19 ms
4,348 KB
testcase_21 AC 63 ms
4,348 KB
testcase_22 AC 65 ms
7,188 KB
testcase_23 AC 66 ms
7,188 KB
testcase_24 AC 63 ms
7,188 KB
testcase_25 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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":" ");
        }
    }
}
0