QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#806947 | #9874. Matrix Construction | ItzDesert | WA | 6ms | 3632kb | C++17 | 4.5kb | 2024-12-09 17:14:51 | 2024-12-09 17:14:52 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int a[1010][1010];
bool check(int n,int m) {
set<int> s;
for(int i = 1;i<=n;i++) {
for(int j = 1;j<=m;j++) {
if(i>1) {
int d = a[i][j]+a[i-1][j];
if(s.find(d)!=s.end())
{return false;
}
s.insert(d);
}
if(j>1) {
int d = a[i][j]+a[i][j-1];
if(s.find(d)!=s.end())
{return false;
}
s.insert(d);
}
}
}
return true;
}
void solve()
{
//nm存在偶数是容易的.
//1 3 5 7
//2 4 6 8
//9 11 13 15
//10 12 14 16
//显然ok.
//如果均奇数
//3、5、14、10、16、12、9、8、7、17、13、
//1 2 3
//8 6 4
//9 7 5
//1 2 3 4 5 6 7
//21 19 17 15 13 11 9
//还是不行,tm怎么这么难啊!!!
//1 2 3
//5 6 4
//7 8 9
//1 2 3 4 5
//7 8 9 10 6
//11 12 13 14 15.
//17 18 19 20 16
//21 22 23 24 25
int n,m,f = 0;
cin>>n>>m;
cout<<"YES"<<'\n';
if(n%2==0||m%2==0)
{
if(n%2==1&&m%2==0) {
swap(n,m);
f = 1;
}
int ot = 1,et = 2;
for(int i = 1;i<=n;i++) {
if(i&1)
{
for(int j = 1;j<=m;j++) {
a[i][j] = ot;
ot+=2;
}
} else {
for(int j = 1;j<=m;j++) {
a[i][j] = et;
et+=2;
}
}
}
if(n&1) {
for(int i = 1;i<=n;i++) {
for(int j = 1;j<=m;j++) {
}
}
for(int j = 1;j<=m;j++) a[n][j] = n*m-m+j;
}
if(f) {
for(int j = 1;j<=m;j++) {
for(int i = 1;i<=n;i++) {
cout<<a[i][j]<<" ";
}
cout<<'\n';
}
} else {
for(int i = 1;i<=n;i++) {
for(int j = 1;j<=m;j++) {
cout<<a[i][j]<<" ";
}
cout<<'\n';
}
}
}
else {
int tot = 0;
for(int i = 1;i<=n;i++) {
if(i%2==1) {
for(int j = 1;j<=m;j++) a[i][j] = ++tot;
} else {
for(int j = 2;j<=m;j++) a[i][j] = ++tot;
a[i][1] = ++tot;
}
}
for(int i = 1;i<=n;i++) {
for(int j = 1;j<=m;j++) {
cout<<a[i][j]<<" ";
}
cout<<'\n';
}
}
if(!check(n,m)) {
cout<<"nooo!!!"<<endl;
}
}
int main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
// int b[27],c[22][22];
// int n = 3,m = 5,fuck = 0;
// for(int i = 0;i<n*m;i++) b[i] = i;
// do
// {
// fuck++;
// for(int i = 0;i<n*m;i++) {
// int x = i/m,y = i%m;
// c[x+1][y+1] = b[i]+1;
// }
// // for(int i = 1;i<=n;i++) {
// // for(int j = 1;j<=m;j++) {
// // cout<<c[i][j]<<" ";
// // }
// // cout<<'\n';
// // }
// //check.
// bool f =true;
// set<int> s;
// for(int i = 1;i<=n;i++) {
// for(int j = 1;j<=m;j++) {
// if(i>1) {
// int d = c[i][j]+c[i-1][j];
// if(s.find(d)!=s.end())
// {f = false;
// goto out;
// }
// s.insert(d);
// }
// if(j>1) {
// int d = c[i][j]+c[i][j-1];
// if(s.find(d)!=s.end())
// {f = false;
// goto out;
// }
// s.insert(d);
// }
// }
// }
// out:
// if(f) {
// for(int i = 1;i<=n;i++) {
// for(int j = 1;j<=m;j++) {
// cout<<c[i][j]<<" ";
// }
// cout<<'\n';
// }
// break;
// }
// } while (next_permutation(b,b+n*m));
int T = 1;
cin>>T;
while (T--)
{
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3592kb
input:
2 1 1 2 3
output:
YES 1 YES 1 3 5 2 4 6
result:
ok All test cases passed. (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 6ms
memory: 3632kb
input:
361 4 9 11 12 16 14 3 7 17 13 1 19 12 3 15 19 11 3 8 18 13 10 8 13 9 18 14 11 7 13 6 16 12 13 1 6 11 15 18 19 5 6 17 19 2 3 17 11 16 19 6 14 5 9 7 2 5 11 15 16 3 15 7 11 16 2 19 15 5 19 2 17 13 12 3 5 19 14 6 3 18 2 16 4 6 8 10 9 17 4 5 16 17 9 16 11 6 9 16 5 3 19 18 9 13 9 12 19 6 13 17 15 13 7 12 ...
output:
YES 1 3 5 7 9 11 13 15 17 2 4 6 8 10 12 14 16 18 19 21 23 25 27 29 31 33 35 20 22 24 26 28 30 32 34 36 YES 1 2 23 24 45 46 67 68 89 90 111 112 3 4 25 26 47 48 69 70 91 92 113 114 5 6 27 28 49 50 71 72 93 94 115 116 7 8 29 30 51 52 73 74 95 96 117 118 9 10 31 32 53 54 75 76 97 98 119 120 11 ...
result:
wrong answer Duplicate sum found for adjacent elements at (2,1) and (3,1) (test case 3)