結果
問題 | No.401 数字の渦巻き |
ユーザー |
![]() |
提出日時 | 2016-07-22 22:28:24 |
言語 | C++14 (gcc 8.3.0) |
結果 |
AC
|
実行時間 | 4 ms |
コード長 | 1,421 Byte |
コンパイル時間 | 1,460 ms |
使用メモリ | 1,544 KB |
最終ジャッジ日時 | 2019-11-26 09:47:48 |
テストケース
テストケース表示入力 | 結果 | 実行時間 使用メモリ |
---|---|---|
01.txt | AC | 4 ms
1,532 KB |
02.txt | AC | 3 ms
1,532 KB |
03.txt | AC | 4 ms
1,536 KB |
04.txt | AC | 4 ms
1,532 KB |
05.txt | AC | 4 ms
1,536 KB |
06.txt | AC | 3 ms
1,528 KB |
07.txt | AC | 3 ms
1,532 KB |
08.txt | AC | 3 ms
1,540 KB |
09.txt | AC | 3 ms
1,536 KB |
10.txt | AC | 4 ms
1,532 KB |
11.txt | AC | 3 ms
1,540 KB |
12.txt | AC | 3 ms
1,540 KB |
13.txt | AC | 3 ms
1,540 KB |
14.txt | AC | 4 ms
1,536 KB |
15.txt | AC | 3 ms
1,540 KB |
16.txt | AC | 3 ms
1,536 KB |
17.txt | AC | 3 ms
1,536 KB |
18.txt | AC | 3 ms
1,536 KB |
19.txt | AC | 3 ms
1,536 KB |
20.txt | AC | 3 ms
1,540 KB |
21.txt | AC | 4 ms
1,540 KB |
22.txt | AC | 4 ms
1,536 KB |
23.txt | AC | 3 ms
1,540 KB |
24.txt | AC | 3 ms
1,544 KB |
25.txt | AC | 3 ms
1,544 KB |
26.txt | AC | 4 ms
1,540 KB |
27.txt | AC | 3 ms
1,544 KB |
28.txt | AC | 4 ms
1,540 KB |
29.txt | AC | 4 ms
1,540 KB |
30.txt | AC | 4 ms
1,540 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #define int long long // <-----!!!!!!!!!!!!!!!!!!! #define rep(i,n) for (int i=0;i<(n);i++) #define rep2(i,a,b) for (int i=(a);i<(b);i++) #define rrep(i,n) for (int i=(n)-1;i>=0;i--) #define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--) #define all(a) (a).begin(),(a).end() #define printV(v) for(auto&& x : v){cerr << x << " ";} cerr << endl #define printVV(vv) for(auto&& v : vv){for(auto&& x : v){cerr << x << " ";}cerr << endl;} typedef long long ll; typedef pair<int, int> Pii; typedef pair<ll, ll> Pll; typedef tuple<int, int, int> TUPLE; typedef vector<int> V; typedef vector<V> VV; typedef vector<VV> VVV; typedef vector<vector<int>> Graph; const int inf = 1e9; const int mod = 1e9 + 7; // N, E, S, W const int dx[4] = {-1, 0, 1, 0}; const int dy[4] = { 0, 1, 0, -1}; int n; inline bool inside(int x, int y) { return 0 <= x && x < n && 0 <= y && y < n; } signed main() { std::ios::sync_with_stdio(false); std::cin.tie(0); cin >> n; VV a(n, V(n)); int x = 0, y = 0; int d = 1; rep(i, n * n) { a[x][y] = i + 1; if (!inside(x + dx[d], y + dy[d]) || a[x + dx[d]][y + dy[d]] != 0) { d = (d + 1) % 4; } x += dx[d], y += dy[d]; } rep(i, n) { rep(j, n) { cout << (j != 0 ? " " : "") << setfill('0') << setw(3) << a[i][j]; } cout << endl; } }