結果
問題 | No.401 数字の渦巻き |
ユーザー |
![]() |
提出日時 | 2016-07-22 22:27:39 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 589 bytes |
コンパイル時間 | 1,248 ms |
コンパイル使用メモリ | 159,396 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-06 08:58:53 |
合計ジャッジ時間 | 2,146 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 30 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:8:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 8 | scanf("%d", &N); | ~~~~~^~~~~~~~~~
ソースコード
#include<bits/stdc++.h>using namespace std;int main(){int N, S[30][30] = {{}};scanf("%d", &N);int sx = -1, sy = 0, sd = 0;const int dy[] = {0, 1, 0, -1}, dx[] = {1, 0, -1, 0};for(int i = 1; i <= N * N; i++) {int nx = sx + dx[sd], ny = sy + dy[sd];while(nx < 0 || ny < 0 || nx >= N || ny >= N || S[ny][nx] > 0) {sd = (sd + 1) % 4;nx = sx + dx[sd], ny = sy + dy[sd];}S[ny][nx] = i;sx = nx, sy = ny;}for(int i = 0; i < N; i++) {for(int j = 0; j < N; j++) {printf("%03d%c", S[i][j], " \n"[j == N - 1]);}}}