提出 #38845950
ソースコード 拡げる
#include <bits/stdc++.h>
using namespace std;
constexpr int max_n=100;
int a[max_n+1][max_n+2];
void test(){
int n;
scanf("%d",&n);
if(n==2){
puts("No");
return;
}
puts("Yes");
if((n&1)){
const int m=n+1;
for(int i=1; i<=n; i+=2){
int now=i;
for(int j=1; j<=n; ++j){
const int col=j<=i?i:(n-i);
a[j][now]=col;
++now>m&&(now=1);
a[j][now]=col;
}
}
for(int i=1; i<=n; ++i){
for(int j=1; j<=n; ++j)
printf("%d ",a[i][j]);
printf("%d\n",a[i][m]);
}
return;
}
const int m=n+1;
for(int i=1; i<=n; ++i)
a[i][i]=a[i][i+1]=n;
for(int j=2; j<=n; ++j)
a[j%n+1][j]=a[(j+1)%n+1][j]=n-1;
a[2][1]=a[n][1]=a[2][m]=a[1][m]=2;
a[3][1]=a[3][m]=1;
for(int i=3,ed=n-3; i<=ed; i+=2){
int now=i+1;
for(int j=1; j<=m; ++j){
const int col=j<=i?i:(m-i);
a[now][j]=col;
++now>n&&(now=1);
a[now][j]=col;
}
}
for(int i=1; i<=n; ++i){
for(int j=1; j<=n; ++j)
printf("%d ",a[i][j]);
printf("%d\n",a[i][m]);
}
}
int main(){
// test();
int t;
for(scanf("%d",&t); t; test(),--t);
return 0;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | B - Summation By Construction |
| ユーザ | wangzhifang |
| 言語 | C++ (GCC 9.2.1) |
| 得点 | 800 |
| コード長 | 1113 Byte |
| 結果 | AC |
| 実行時間 | 76 ms |
| メモリ | 3724 KiB |
コンパイルエラー
./Main.cpp: In function ‘void test()’:
./Main.cpp:7:7: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
7 | scanf("%d",&n);
| ~~~~~^~~~~~~~~
./Main.cpp: In function ‘int main()’:
./Main.cpp:56:11: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
56 | for(scanf("%d",&t); t; test(),--t);
| ~~~~~^~~~~~~~~
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 800 / 800 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | 01.txt |
| All | 01.txt, 02.txt, 03.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 01.txt | AC | 4 ms | 3604 KiB |
| 02.txt | AC | 38 ms | 3600 KiB |
| 03.txt | AC | 76 ms | 3724 KiB |