結果
| 問題 |
No.401 数字の渦巻き
|
| コンテスト | |
| ユーザー |
どらら
|
| 提出日時 | 2016-07-22 22:55:29 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,145 bytes |
| コンパイル時間 | 580 ms |
| コンパイル使用メモリ | 79,160 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-06 09:11:45 |
| 合計ジャッジ時間 | 1,488 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 30 |
ソースコード
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <iostream>
#include <queue>
#include <list>
#include <stack>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
int field[40][40];
int vx[4] = {1,0,-1,0};
int vy[4] = {0,1,0,-1};
int main(){
int N;
cin >> N;
int cnt = 1;
int ang = 0;
int x = 0, y = 0;
rep(i,40) rep(j,40) field[i][j] = 0;
while(true){
field[y][x] = cnt;
if(cnt == N*N) break;
cnt++;
int nx = x + vx[ang];
int ny = y + vy[ang];
if(0<=nx && nx<N && 0<=ny && ny<N && field[ny][nx] == 0){
x = nx;
y = ny;
}else{
ang = (ang+1)%4;
x = x + vx[ang];
y = y + vy[ang];
}
}
rep(i,N){
rep(j,N){
if(j!=0) printf(" ");
printf("%03d", field[i][j]);
}
printf("\n");
}
return 0;
}
どらら