結果
| 問題 |
No.401 数字の渦巻き
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-07-17 22:13:23 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 794 bytes |
| コンパイル時間 | 568 ms |
| コンパイル使用メモリ | 71,680 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-27 10:05:40 |
| 合計ジャッジ時間 | 1,431 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 30 |
ソースコード
#include <iostream>
#include <vector>
#include <stdio.h>
using namespace std;
void SetValue(vector<vector<int>> &A,int stX,int stY,int W,int &V)
{
int i,j;
//上行
i=stX;
j=stY;
while (j<stY+W){
A[i][j++]=V++;
}
j--;
i++;
//右列
while (i<stX+W){
A[i++][j]=V++;
}
i--;
//下行
j--;
while (j>=stY){
A[i][j--]=V++;
}
//左列
j++;
i--;
while (i>stX){
A[i--][j]=V++;
}
}
int main(int argc, char* argv[])
{
int N;
cin>>N;
vector<vector<int>> A(N,vector<int>(N));
int V=1;
int stX=0;
int stY=0;
int W=N;
while(true){
SetValue(A,stX,stY,W,V);
stX++;
stY++;
W-=2;
if (W<=0){
break;
}
}
int i,j;
for (i=0;i<N;i++){
for (j=0;j<N;j++){
if (j<N-1){
printf("%03d ",A[i][j]);
}else{
printf("%03d\n",A[i][j]);
}
}
}
return 0;
}