結果
問題 | No.401 数字の渦巻き |
ユーザー |
|
提出日時 | 2016-10-07 12:44:17 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,084 bytes |
コンパイル時間 | 1,002 ms |
コンパイル使用メモリ | 107,428 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-21 19:09:26 |
合計ジャッジ時間 | 2,185 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 30 |
ソースコード
#define _USE_MATH_DEFINES #include <cstdio> #include <iostream> #include <sstream> #include <fstream> #include <iomanip> #include <algorithm> #include <cmath> #include <complex> #include <string> #include <vector> #include <list> #include <queue> #include <stack> #include <set> #include <map> #include <bitset> #include <numeric> #include <limits> #include <climits> #include <cfloat> #include <functional> #include <iterator> using namespace std; const int dy[] = {0, 1, 0, -1}; const int dx[] = {1, 0, -1, 0}; int main() { int n; cin >> n; vector<vector<int> > v(n, vector<int>(n)); int y = 0; int x = -1; int cnt = 1; for(int i=0; i<2*n-1; ++i){ int len = (2 * n - i) / 2; for(int j=0; j<len; ++j){ y += dy[i%4]; x += dx[i%4]; v[y][x] = cnt; ++ cnt; } } for(int i=0; i<n; ++i){ cout << setw(3) << setfill('0') << v[i][0]; for(int j=1; j<n; ++j) cout << ' ' << setw(3) << setfill('0') << v[i][j]; cout << endl; } return 0; }