結果

問題 No.1974 2x2 Flipper
ユーザー RiRinbaru
提出日時 2025-04-04 02:51:46
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 74 ms / 2,000 ms
コード長 2,044 bytes
コンパイル時間 3,990 ms
コンパイル使用メモリ 222,372 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-04-04 02:51:54
合計ジャッジ時間 7,868 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, p, n) for (ll i = p; i < (ll)(n); i++)
#define rep2(i, p, n) for (ll i = p; i >= (ll)(n); i--)
using namespace std;
using ll = long long;
using ld = long double;
const double pi = 3.141592653589793;
const long long inf = 2 * 1e9;
const long long linf = 4 * 1e18;
const ll mod1 = 1000000007;
const ll mod2 = 998244353;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}

// atcoder
#include <atcoder/all>
using namespace atcoder;
using mint1 = modint1000000007;
using mint2 = modint998244353;

vector<pair<ll, ll>> base = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};

int main()
{

    //////////////////
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    //////////////////

    ll H, W;
    cin >> H >> W;
    if (H%2==0 && W%2==0) {
        cout << H * W << endl;
        rep(i, 0, H) {
            rep(j, 0, W) {
                cout << 1 << " ";
            }
            cout << endl;
        }
    }
    else if (W%2==0) {
        cout << (H - 1) * W << endl;
        rep(i, 0, H - 1) {
            rep(j, 0, W) {
                cout << 1 << " ";
            }
            cout << endl;
        }
        rep(j, 0, W) {
            cout << 0 << " ";
        }
        cout << endl;
    }
    else if(H%2==0) {
        cout << H * (W-1) << endl;
        rep(i, 0, H) {
            rep(j, 0, W - 1) {
                cout << 1 << " ";
            }
            cout << 0;
            cout << endl;
        }
    }
    else {
        cout << H * W - max(H, W) << endl;
        rep(i, 0, H) {
            rep(j, 0, W) {
                if (i==j || (i==H-1 && j>i) || (j==W-1 && i>j)) {
                    cout << 0 << " ";
                }
                else {
                    cout << 1 << " ";
                }
            }
            cout << endl;
        }
    }
}
0