Submission #71658343
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
const int maxn=105;
int a[maxn][maxn];
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n;
cin>>n;
int r=0,c=(n-1)/2;
a[r][c]=1;
for (int i=2;i<=n*n;i++)
{
int nxtr=(r-1+n)%n,nxtc=(c+1)%n;
if (!a[nxtr][nxtc])
{
a[nxtr][nxtc]=i;
r=nxtr;
c=nxtc;
}
else
{
nxtr=(r+1)%n;
a[nxtr][c]=i;
r=nxtr;
}
}
for (int i=0;i<n;i++)
{
for (int j=0;j<n;j++)
cout<<a[i][j]<<" ";
cout<<'\n';
}
}
Submission Info
| Submission Time | |
|---|---|
| Task | B - Magic Square |
| User | Alliy666 |
| Language | C++23 (GCC 15.2.0) |
| Score | 200 |
| Code Size | 697 Byte |
| Status | AC |
| Exec Time | 1 ms |
| Memory | 3760 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 200 / 200 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00_sample_00.txt, 00_sample_01.txt |
| All | 00_sample_00.txt, 00_sample_01.txt, 01_test_00.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_sample_00.txt | AC | 1 ms | 3560 KiB |
| 00_sample_01.txt | AC | 1 ms | 3612 KiB |
| 01_test_00.txt | AC | 1 ms | 3560 KiB |
| 01_test_01.txt | AC | 1 ms | 3544 KiB |
| 01_test_02.txt | AC | 1 ms | 3544 KiB |
| 01_test_03.txt | AC | 1 ms | 3708 KiB |
| 01_test_04.txt | AC | 1 ms | 3708 KiB |
| 01_test_05.txt | AC | 1 ms | 3760 KiB |
| 01_test_06.txt | AC | 1 ms | 3612 KiB |
| 01_test_07.txt | AC | 1 ms | 3672 KiB |
| 01_test_08.txt | AC | 1 ms | 3668 KiB |
| 01_test_09.txt | AC | 1 ms | 3672 KiB |
| 01_test_10.txt | AC | 1 ms | 3672 KiB |