QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#856221 | #8485. Magic Square | ship2077 | WA | 1ms | 3968kb | C++14 | 1.1kb | 2025-01-13 19:15:33 | 2025-01-13 19:15:34 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
constexpr int M=1005;
int n,sum,r[M],c[M],a[M][M];
vector<int>posx,posy;
int read(){
int x=0;char ch=getchar();
while (!isdigit(ch)) ch=getchar();
while (isdigit(ch)) x=x*10+ch-48,ch=getchar();
return x;
}
int main(){
n=read();sum=n*(n*n+1)/2;
for (int i=1;i<=n;i++)
for (int j=1;j<=n;j++)
a[i][j]=read(),r[i]+=a[i][j],c[j]+=a[i][j];
for (int i=1;i<=n;i++) if (r[i]!=sum) posx.emplace_back(i);
for (int i=1;i<=n;i++) if (c[i]!=sum) posy.emplace_back(i);
if (posx.size()==2&&posy.size()==2) return printf("%d %d\n%d %d\n",posx[0],posy[0],posx[1],posy[1]),0;
if (posx.size()==2){
const int x=posx[0],y=posx[1];
for (int i=1;i<=n;i++)
if (r[x]-a[x][i]+a[y][i]==r[y]-a[y][i]+a[x][i])
return printf("%d %d\n%d %d\n",x,i,y,i),0;
}
if (posy.size()==2){
const int x=posy[0],y=posy[1];
for (int i=1;i<=n;i++)
if (c[x]-a[i][x]+a[i][y]==c[y]-a[i][y]+a[i][x])
return printf("%d %d\n%d %d\n",i,x,i,y),0;
}
printf("1 1 1 1\n");
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3840kb
input:
3 6 9 2 3 5 7 8 1 4
output:
1 1 3 3
result:
ok OK
Test #2:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
4 16 3 2 13 5 10 11 8 9 6 7 12 1 15 14 4
output:
2 1 2 4
result:
ok OK
Test #3:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
3 8 1 6 3 5 7 4 2 9
output:
3 2 3 3
result:
ok OK
Test #4:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
4 9 12 7 6 4 2 14 15 16 13 1 3 5 8 11 10
output:
2 2 3 3
result:
ok OK
Test #5:
score: 0
Accepted
time: 1ms
memory: 3712kb
input:
5 15 17 1 8 24 3 10 19 21 12 16 23 7 14 6 22 4 13 20 5 9 11 25 2 18
output:
3 5 4 5
result:
ok OK
Test #6:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
6 14 34 12 5 16 30 27 2 22 9 20 31 18 28 13 36 11 4 19 6 26 1 24 35 10 33 17 29 15 8 23 7 21 32 25 3
output:
3 2 5 4
result:
ok OK
Test #7:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
7 39 28 30 1 19 10 48 47 29 38 8 27 18 7 6 37 46 17 35 26 9 23 12 21 41 3 43 32 31 20 22 49 11 2 40 14 45 5 25 36 34 16 15 4 13 33 44 42 24
output:
2 4 3 7
result:
ok OK
Test #8:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
8 42 22 20 47 19 21 48 41 55 11 13 50 14 12 49 56 57 3 5 58 6 4 63 64 7 59 61 2 62 60 1 8 34 30 28 39 27 29 40 33 15 51 53 10 54 52 9 16 18 46 44 23 43 45 24 17 26 38 36 31 35 37 32 25
output:
1 1 1 7
result:
ok OK
Test #9:
score: -100
Wrong Answer
time: 0ms
memory: 3968kb
input:
9 23 69 1 45 47 34 12 58 80 64 29 51 5 16 75 62 27 40 53 18 31 66 77 55 42 7 49 63 19 41 76 6 65 52 17 30 13 59 81 35 37 24 2 48 70 3 20 71 25 36 14 73 38 60 74 39 61 15 26 4 72 28 50 43 8 21 56 67 54 32 78 10 33 79 11 46 57 44 22 68 9
output:
3 2 6 9
result:
wrong answer Incorrect sum in row 2