結果
問題 | No.401 数字の渦巻き |
ユーザー |
|
提出日時 | 2016-11-23 23:23:06 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 658 bytes |
コンパイル時間 | 1,543 ms |
コンパイル使用メモリ | 170,444 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-27 10:25:21 |
合計ジャッジ時間 | 2,310 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 30 |
ソースコード
#include <bits/stdc++.h>using namespace std;const int dx[] = { 0, 1, 0, -1 };const int dy[] = { 1, 0, -1, 0 };int in_range( int n, int x, int y ){return 0 <= x and x < n and 0 <= y and y < n;}signed main(){int N; cin >> N;vector< vector< int > > G( N, vector< int >( N ) );int x = 0, y = 0, d = 0;for( int i = 1; i <= N * N; ++i ){G[ x ][ y ] = i;if( not in_range( N, x + dx[ d ], y + dy[ d ] ) or G[ x + dx[ d ] ][ y + dy[ d ] ] )++d, d %= 4;x += dx[ d ], y += dy[ d ];}for( int i = 0; i < N; ++i )for( int j = 0; j < N; ++j )printf( "%03d%c", G[ i ][ j ], " \n"[ j + 1 == N ] );return 0;}