結果

問題 No.3092 Tired Queen
ユーザー ripity
提出日時 2025-04-06 15:59:06
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 896 bytes
コンパイル時間 2,338 ms
コンパイル使用メモリ 201,392 KB
実行使用メモリ 13,908 KB
最終ジャッジ日時 2025-04-06 15:59:13
合計ジャッジ時間 5,478 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#include <atcoder/modint>
using namespace atcoder;

using ll = long long;
using mint = modint1000000007;

int main() {
  int N;
  cin >> N;
  using P = pair<int, int>;
  vector<P> seq;
  for(int n = N; n >= 2; n -= 2) {
    const int p = N - n + 1;
    seq.push_back(P{p, p});
    seq.push_back(P{p + 1, p});
    for(int r = p + 2; r <= N; r++) {
      seq.push_back(P{r, p + 1});
      seq.push_back(P{r, p});
    }
    for(int c = N; c >= p + 1; c--) {
      seq.push_back(P{p, c});
      seq.push_back(P{p + 1, c});
    }
  }
  if(N % 2 == 1) {
    seq.push_back(P{N, N});
  }
  const int K = N * N;
  vector ans(N, vector<int>(N));
  for(int i = 0; i < K; i++) {
    auto [r, c] = seq[i];
    ans[r - 1][c - 1] = i + 1;
  }
  for(int i = 0; i < N; i++) {
    for(int j = 0; j < N; j++) {
      cout << ans[i][j] << " \n"[j == N - 1];
    }
  }
}
0