結果
| 問題 | No.3092 Tired Queen |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-12-02 17:34:49 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 78 ms / 2,000 ms |
| コード長 | 1,219 bytes |
| 記録 | |
| コンパイル時間 | 1,841 ms |
| コンパイル使用メモリ | 198,864 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2025-12-02 17:34:56 |
| 合計ジャッジ時間 | 6,517 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 41 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N; cin >> N; vector<vector<int>> A(N,vector<int>(N));
int nh=0,nw=0;
int c=0;//周を管理する
for(int a=1; a<=N*N; a++){
// cerr<<"start "<<"nh="<<nh<<" nw="<<nw<<" a="<<a<<" c="<<c<<endl;
A[nh][nw]=a;
//縦に動くとき
if(a%2){
if(nh==c||nh==N-1-c){
if(nw==N-1-c)nh++;
else nw++;
}
else if(nw==c||nw==N-1-c){
if(nh==N-1-c)nw++;
else nh++;
}
// cerr<<"nh="<<nh<<" nw="<<nw<<" a="<<a<<" c="<<c<<endl;
}
//斜めに動くとき
else {
if(nh==N-1-c&&nw==N-1-c){
c++;nh=c,nw=c;
}
else swap(nh,nw);
// cerr<<"nh="<<nh<<"nw="<<nw<<"a="<<a<<"c="<<c<<endl;
}
// for(int i=0; i<N; i++){
// for(int j=0; j<N; j++)cerr<<A[i][j]<<" ";
// cerr<<endl;
// }cerr<<endl;
}
for(int i=0; i<N; i++){
for(int j=0; j<N; j++)cout<<A[i][j]<<" ";
cout<<endl;
}
}