結果
問題 | No.401 数字の渦巻き |
ユーザー |
![]() |
提出日時 | 2016-07-22 22:29:47 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,471 bytes |
コンパイル時間 | 1,060 ms |
コンパイル使用メモリ | 113,636 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-06 09:00:37 |
合計ジャッジ時間 | 1,987 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 30 |
ソースコード
#include <iostream>#include <algorithm>#include <cmath>#include <vector>#include <complex>#include <queue>#include <deque>#include <set>#include <map>#include <unordered_set>#include <unordered_map>#include <iomanip>#include <assert.h>#include <array>#include <cstdio>#include <cstring>#include <random>#include <functional>#include <numeric>#include <bitset>#include <fstream>using namespace std;#define REP(i,a,b) for(int i=a;i<(int)b;i++)#define rep(i,n) REP(i,0,n)#define all(c) (c).begin(), (c).end()#define zero(a) memset(a, 0, sizeof a)#define minus(a) memset(a, -1, sizeof a)#define watch(a) { cout << #a << " = " << a << endl; }template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }typedef long long ll;int const inf = 1<<29;int a[33][33];int dx[4] = {-1,0,1,0};int dy[4] = {0,-1,0,1};template<class T> constexpr bool in_range(T y, T x, T H, T W) { return 0<=y&&y<H&&0<=x&&x<W; }int main() {int N; cin >> N;int y = 0, x = 0;int k = 2;int cnt = 1;while(cnt <= N * N) {a[y][x] = cnt++;int ny = y + dy[k], nx = x + dx[k];if(!in_range(ny, nx, N, N) || a[ny][nx]) {k ++;k %= 4;ny = y + dy[k], nx = x + dx[k];}y = ny, x = nx;}rep(i, N) rep(j, N) {printf("%03d%c", a[i][j], j == N-1 ? '\n' : ' ');}return 0;}