QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#816094 | #9799. Magical Palette | Dixiky_215 | WA | 41ms | 11764kb | C++20 | 1.9kb | 2024-12-15 22:03:47 | 2024-12-15 22:04:05 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int MAXN=1e6+7;
int n,m;
ll a[MAXN],b[MAXN];
ll c[MAXN];
int vis[MAXN];
bool check()
{
int tot=0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
c[++tot]=(a[i]*b[j])%(n*m);
}
}
sort(c+1,c+1+n*m);
for(int i=1;i<=n*m;i++)
{
if(c[i]!=i-1) return 0;
}
return 1;
}
int num=0;
void dfs2(int x,int pre)
{
if(x==m+1)
{
// if(!check()) return;
num++;
for(int i=1;i<=n;i++) cout<<a[i]<<' ';cout<<'\n';
for(int i=1;i<=m;i++) cout<<b[i]<<" ";cout<<'\n';
cout<<endl;
if(num>=100||a[1]!=1) exit(0);
return;
}
for(int i=pre+1;i<=n*m;i++)
{
bool flag=1;
for(int j=1;j<=n;j++)
{
ll sss=(i*a[j])%(n*m);
if(vis[sss]) flag=0;
vis[sss]++;
}
if(flag)
{
b[x]=i;
dfs2(x+1,i);
}
for(int j=1;j<=n;j++)
{
ll sss=(i*a[j])%(n*m);
vis[sss]--;
}
}
return;
}
void dfs1(int x,int pre)
{
if(x==n+1)
{
dfs2(1,0);
return;
}
for(int i=pre+1;i<=n*m;i++)
{
a[x]=i;
dfs1(x+1,i);
}
return;
}
bool work(int x)
{
for(int i=2;i*i<=x;i++)
{
if(x%i==0) return 0;
}
return 1;
}
int main()
{
// ios::sync_with_stdio(false);
// cin.tie(0);
// cout.tie(0);
// cin>>n>>m;
// dfs1(1,0);
// cout<<"-1";
int t;
cin>>t;
while(t--)
{
cin>>n>>m;
int nn=n,mm=m;
if(n>m) swap(n,m);
if(gcd(n,m)!=1)
{
cout<<"No\n";
continue;
}
for(int i=1;i<=n;i++) a[i]=1LL+(i-1)*m;
for(int i=1;i<=m;i++) b[i]=1LL+(i-1)*n;
// if(check()) cout<<"Yes\n";
// else cout<<"No\n";
cout<<"Yes\n";
if(nn>mm)
{
for(int i=1;i<=m;i++) cout<<b[i]<<" ";cout<<'\n';
for(int i=1;i<=n;i++) cout<<a[i]<<" ";cout<<'\n';
}
else
{
for(int i=1;i<=n;i++) cout<<a[i]<<" ";cout<<'\n';
for(int i=1;i<=m;i++) cout<<b[i]<<" ";cout<<'\n';
}
}
return 0;
}
/*
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 7728kb
input:
2 2 3 2 2
output:
Yes 1 4 1 3 5 No
result:
ok 2 cases (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 41ms
memory: 11764kb
input:
1 1 1000000
output:
Yes 1 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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 1...
result:
wrong answer Integer parameter [name=b[1000000]] equals to 1000000, violates the range [0, 999999] (test case 1)