結果

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

ソースコード

diff #

#include <iostream>

using namespace std;
int main(){
    int i,j,h,w; cin >> h >> w;
    if(h==1){
        cout << 0 << endl;
        for(i=0;i<w;i++) cout << 0 << " ";
        cout << endl;
        return 0;
    }
    if(w==1){
        cout << 0 << endl;
        for(i=0;i<h;i++) cout << 0 << "\n";
        return 0;
    }
    if(h&1 && w&1){
        int ans = 0;
        if(h>=w){
            cout << h*(w - 1) << endl;
            for(i=0;i<w;i++){
                for(j=0;j<w;j++){
                    if(i==j) cout << 0 <<  " ";
                    else cout << 1 << " ";  
                }
                cout << endl;
            }
            for(i=w;i<h;i++){
                for(j=0;j<w - 1;j++){
                    cout << 1 << " ";
                }
                cout << 0 << " ";
                cout << endl;
            }
        }else{
            cout << w*(h - 1) << endl;
            for(i=0;i<h;i++){
                for(j=0;j<h;j++){
                    if(i==j) cout << 0 << " ";
                    else cout << 1 << " ";
                }
                for(j=h;j<w;j++){
                    if(i<h - 1) cout << 1 << " ";
                    else cout << 0 << " ";
                }
                cout << "\n";
            }
        }
    }else if(h&1){
        cout << (h - 1)*w << endl;
        for(i=0;i<h - 1;i++){
            for(j=0;j<w;j++) cout << 1 << " ";
            cout << endl;
        }
        for(i=0;i<w;i++) cout << 0 << " ";
        cout << endl;
    }else if(w&1){
        cout << h*(w - 1) << endl;
        for(i=0;i<h;i++){
            for(j=0;j<w - 1;j++) cout << 1 << " ";
            cout << 0 << "\n";
        }
    }else{
        cout << h*w << endl;
        for(i=0;i<h;i++){
            for(j=0;j<w;j++) cout << 1 << " ";
            cout << endl;
        }
    }
}
0