結果

問題 No.3721 Absurd Basic Constructive
コンテスト
ユーザー l__l
提出日時 2026-09-19 14:31:49
言語 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
結果
WA  
実行時間 -
コード長 1,495 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 8,360 ms
コンパイル使用メモリ 389,236 KB
実行使用メモリ 10,048 KB
最終ジャッジ日時 2026-09-19 14:32:15
合計ジャッジ時間 11,797 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 13 WA * 34
権限があれば一括ダウンロードができます

ソースコード

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;cin >> N;
    int K;cin >> K;
    if(K == 0){
        cout << -1 << nl;
        return 0;
    }
    vector<vector<int>>ans(N,vector<int>(N,-1));
    vector<bool>written(N*N+1);
    int diff = K-1;
    int biggest = N*N;
    pair<int,int>where = {diff/N,diff%N};
    int semi_biggest = N;
    diff %= N;
    pair<int,int>place = {0,diff};
    ans[where.first][where.second] = biggest;
    written[biggest] = true;
    if(ans[place.first][place.second] != biggest){
        ans[place.first][place.second] = semi_biggest;
        written[semi_biggest] = true;
    }
    int current = 1;
    rep(i,N*N){
        int h = i/N;
        int w = i%N;
        
        while(written[current])current++;
        if(ans[h][w] == -1){
            ans[h][w] = current;
            written[current] = true;
        }
    }

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