結果

問題 No.401 数字の渦巻き
ユーザー alcheminalchemin
提出日時 2020-02-03 12:46:15
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,284 bytes
コンパイル時間 2,277 ms
コンパイル使用メモリ 168,796 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 01:42:37
合計ジャッジ時間 2,935 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORTASC(c) sort((c).begin(),(c).end())
#define SORTDESC(c,t) sort((c).begin(),(c).end(), std::greater<t>());
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define VMAX(a) *max_element(ALL(a))
#define VMIN(a) *min_element(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double PI  = acos(-1.0);

using ll = long long;
using namespace std;

int main() {
    ll n;

    cin >> n;

    ll mat[n][n];
    REP(i, n){
        REP(j, n){
            mat[i][j] = 0;
        }
    }

    ll num = 1, row = 0, col = 0;
    while(num <= n*n){
        while(true){
            if (col < n && mat[row][col] == 0){
                mat[row][col] = num;
                num++;
                col++;
            } else {
                row++;
                col--;
                break;
            }
        }

        while(true){
            if (row < n && mat[row][col] == 0){
                mat[row][col] = num;
                num++;
                row++;
            } else {
                row--;
                col--;
                break;
            }
        }

        while(true){
            if (col >= 0 && mat[row][col] == 0){
                mat[row][col] = num;
                num++;
                col--;
            } else {
                row--;
                col++;
                break;
            }
        }

        while(true){
            if (row >= 0 && mat[row][col] == 0){
                mat[row][col] = num;
                num++;
                row--;
            } else {
                row++;
                col++;
                break;
            }
        }
    }

    REP(i, n){
        REP(j, n-1){
            cout << setfill('0') << std::right << setw(3) << mat[i][j] << " ";
        }
        cout << setfill('0') << std::right << setw(3) << mat[i][n-1] << endl;
    }

    return 0;
}
0