結果

問題 No.3721 Absurd Basic Constructive
コンテスト
ユーザー RiRinbaru
提出日時 2026-09-20 11:12:44
言語 C++14
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 46 ms / 2,000 ms
+ 93µs
コード長 1,760 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,432 ms
コンパイル使用メモリ 247,264 KB
実行使用メモリ 11,552 KB
最終ジャッジ日時 2026-09-20 11:12:55
合計ジャッジ時間 9,627 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 47
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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 = (1LL << 61);
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;
}
template <class T>
using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;

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

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

void solve()
{
    ll n, k;
    cin >> n >> k;
    if (k == 0)
    {
        cout << -1 << endl;
        return;
    }
    ll ans[n][n];
    ll p = n * n - k + 1;
    rep(i, 0, n)
    {
        rep(j, 0, i)
        {
            ans[i][j] = p;
            p++;
            if (p == n * n + 1)
            {
                p = 1;
            }
        }
        rep(j, 0, i + 1)
        {
            ans[j][i] = p;
            p++;
            if (p == n * n + 1)
            {
                p = 1;
            }
        }
    }
    rep(i, 0, n)
    {
        rep(j, 0, n)
        {
            cout << ans[i][j] << " ";
        }
        cout << endl;
    }
}

int main()
{

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

    // ll T;
    // cin >> T;
    // while (T--)
    solve();
    return 0;
}
0