結果

問題 No.3721 Absurd Basic Constructive
コンテスト
ユーザー l__l
提出日時 2026-09-19 15:13:10
言語 C++23(gcc16)
(gcc 16.1.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 53 ms / 2,000 ms
+ 211µs
コード長 1,189 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,509 ms
コンパイル使用メモリ 387,896 KB
実行使用メモリ 7,680 KB
最終ジャッジ日時 2026-09-19 15:13:22
合計ジャッジ時間 10,748 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 47
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
#define all(x) x.begin(), x.end()
#define rep(i, limit) for (int i = 0; i < (int)limit; i++)
constexpr char nl = '\n';
constexpr int INF = 1'000'000'000;
constexpr ll LINF = 2'000'000'000'000'000'000LL;
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int N,K;cin >> N >> K;
    if(K == 0){
        cout << -1 << nl;
        return 0;
    }
    K--;
    
    int top_left = N*N - K;
    vector<vector<int>>ans(N,vector<int>(N));
    ans[0][0] = top_left;

    vector<bool>used(N*N+1);
    used[top_left] = true;
    int current = 1;
    for(int i = 0; i < N*N; i++){
        int h = i/N;
        int w = i%N;

        while(used[current])current++;
        if(ans[h][w] == 0){
            ans[h][w] = current;
            used[current] = true;
        }
    }

    rep(i,N){
        rep(j,N){
            cout << ans[i][j] << " ";
        }
        cout << nl;
    }
}
0