結果
問題 | No.401 数字の渦巻き |
ユーザー |
![]() |
提出日時 | 2018-02-20 20:40:07 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,147 bytes |
コンパイル時間 | 932 ms |
コンパイル使用メモリ | 88,908 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-22 07:34:13 |
合計ジャッジ時間 | 1,913 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 30 |
ソースコード
#include <iostream>#include <vector>#include <string>#include <cstring>#include <math.h>#include <cmath>#include <limits.h>#include <map>#include <set>#include <queue>#include <algorithm>#include <functional>#include <stdio.h>using namespace std;long long MOD = 1000000007;int N;bool isOK( int x, int y ) {return x >= 0 && y >= 0 && x < N && y < N;}int main() {cin >> N;vector< vector<int> > V( N, vector<int>( N, -1 ) );int D[4][2] = { {1,0}, {0,1}, {-1,0}, {0,-1} };int a = 1;int i = 0;int x = 0, y = 0;int c = 0;V[0][0] = a;while ( true ) {int nx = x + D[i%4][0];int ny = y + D[i%4][1];if ( isOK( nx, ny ) && V[nx][ny] == -1 ) {a++;V[nx][ny] = a;x = nx; y = ny;c = 0;}else { i++; c++; }if ( c == 4 ) { break; }}for ( int y = 0; y < N; y++ ) {for ( int x = 0; x < N; x++ ) {printf( "%03d", V[x][y] );if ( x != N-1 ) { cout << " "; }}cout << endl;}return 0;}