QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#804361 | #9874. Matrix Construction | ucup-team139# | WA | 2ms | 3668kb | C++14 | 1.6kb | 2024-12-07 22:01:30 | 2024-12-07 22:01:30 |
Judging History
answer
#include <bits/stdc++.h>
#define int int64_t
using namespace std;
vector<vector<int> > solve1(int n, int m) {
vector<vector<int> > a(n, vector<int>(m));
int c = 1;
for(int i=0; i<n; ++i) {
for(int j=0; j<m; ++j) {
a[i][j]=c++;
}
}
return a;
}
vector<vector<int> > solve2(int n, int m) {
vector<vector<int> > a(n, vector<int>(m));
int c = 1;
for(int i=0; i<m; ++i) {
for(int j=0; j<n; ++j) {
a[j][i]=c++;
}
}
return a;
}
bitset<2000000> s;
void reset(vector<vector<int> >& a) {
int n = a.size();
int m = a[0].size();
for(int i=0; i<n; ++i) {
for(int j=0; j<m; ++j) {
if(i<n-1) {
int o = a[i][j]+a[i+1][j];
s[o]=0;
}
if(j<m-1) {
int o = a[i][j]+a[i][j+1];
s[o]=0;
}
}
}
}
bool check(vector<vector<int> >& a) {
int n = a.size();
int m = a[0].size();
for(int i=0; i<n; ++i) {
for(int j=0; j<m; ++j) {
if(i<n-1) {
int o = a[i][j]+a[i+1][j];
if(s[o]) {reset(a); return 0;}
s[o]=1;
}
if(j<m-1) {
int o = a[i][j]+a[i][j+1];
if(s[o]) {reset(a); return 0;}
s[o]=1;
}
}
}
reset(a);
return 1;
}
signed main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
/*for(int sum=2; sum<11; ++sum) {
for(int i=1; i<sum; ++i) {
int j=sum-i;
auto a = solve1(i,j);
auto b = solve2(i,j);
if(!check(a) && !check(b)) {
cerr<<"Wrong "<<i<<' '<<j<<endl;
}
}
}
return 0;*/
int t;
cin>>t;
while(t--) {
int n,m;
cin>>n>>m;
auto a = solve1(n,m);
if(!check(a)) a = solve2(n,m);
if(!check(a)) {
cout<<"No\n";
} else {
cout<<"Yes\n";
for(int i=0; i<n; ++i) {
for(int j=0; j<m; ++j) {
cout<<a[i][j]<<' ';
}
cout<<'\n';
}
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3576kb
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: 2ms
memory: 3668kb
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 5 9 13 17 21 25 29 33 2 6 10 14 18 22 26 30 34 3 7 11 15 19 23 27 31 35 4 8 12 16 20 24 28 32 36 Yes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 6...
result:
wrong answer Token parameter [name=ok] equals to "No", doesn't correspond to pattern "[yY][eE][sS]" (test case 4)