結果

問題 No.3721 Absurd Basic Constructive
コンテスト
ユーザー MM
提出日時 2026-09-19 13:49:46
言語 C++23(gcc16)
(gcc 16.2.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
+ 764µs
コード長 1,122 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,583 ms
コンパイル使用メモリ 389,556 KB
実行使用メモリ 9,988 KB
最終ジャッジ日時 2026-09-19 13:50:04
合計ジャッジ時間 10,904 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge7_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 47
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
#include<atcoder/all>
#define chmin(x,y) (x) = min((x),(y))
#define chmax(x,y) (x) = max((x),(y))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vec vector
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back 
#define eb emplace_back

using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;
const ll mod = 998244353;
using mint = modint998244353;
const vector<int> dx = {1,0,-1,0}, dy = {0,1,0,-1};
// using Graph = vector<vector<pair<int,ll>>>;
using Graph = vector<vector<int>>;

int main(){
  // input
  int N,K;
  cin >> N >> K;
  if(K == 0){
    cout << "-1\n";
    return 0;
  }
  
  vector<vector<int>> ans(N,vector<int>(N,-1));
  int large = N * N - K + 1, small = 1;
  rep(i,K){
    ans[i%N][i/N] = large;
    large++;
  }
  assert(large == N*N+1);
  rep(i,N) rep(j,N){
    if(ans[i][j] != -1) continue;
    ans[i][j] = small;
    small++;
  }
  assert(small = N*N-K+1);
  // output
  rep(i,N){
    rep(j,N){
      if(j) cout << " ";
      cout << ans[i][j];
    }
    cout << "\n";
  }
  return 0;
}
0