結果
問題 | No.401 数字の渦巻き |
ユーザー |
![]() |
提出日時 | 2020-04-27 11:07:37 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 879 bytes |
コンパイル時間 | 1,610 ms |
コンパイル使用メモリ | 172,368 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-21 07:36:42 |
合計ジャッジ時間 | 2,619 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 30 |
ソースコード
#include <bits/stdc++.h>using namespace std;int main(){int N;cin >> N;vector<vector<int>> v( N, vector<int>( N ) );int r = 0;int x = 0;int y = 0;int n = 1;v[y][x] = n;for( int i = 0; i < N; i++ ) {for( int j = 0; j < N - r - 1; j++ ) {n++;x++;v[y][x] = n;}if( n >= N * N ) break;for( int j = 0; j < N - r - 1; j++ ) {n++;y++;v[y][x] = n;}if( n >= N * N ) break;for( int j = 0; j < N - r - 1; j++ ) {n++;x--;v[y][x] = n;}if( n >= N * N ) break;for( int j = 0; j < N - r - 2; j++ ) {n++;y--;v[y][x] = n;}if( n >= N * N ) break;n++;x++;v[y][x] = n;if( n >= N * N ) break;r += 2;}for( int i = 0; i < N; i++ ) {for( int j = 0; j < N; j++ ) {char c[16];sprintf( c, "%03d", v[i][j] );if( j ) cout << " ";cout << c;}cout << endl;}}