QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#840384#9799. Magical Palettefrankly6#TL 58ms14172kbC++171.8kb2025-01-02 17:56:382025-01-02 17:56:39

Judging History

你现在查看的是最新测评结果

  • [2025-01-02 17:56:39]
  • 评测
  • 测评结果:TL
  • 用时:58ms
  • 内存:14172kb
  • [2025-01-02 17:56:38]
  • 提交

answer

#include<iostream>
#include<cstdio>
#define int long long
using namespace std;
const int MX=1000010;

int T, N, M;
int ar[MX], br[MX];
bool vis[MX];
int read()
{
    int r=0, f=1; char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9') {r=r*10+ch-'0'; ch=getchar();}
    return r*f;
}
int gcd(int a, int b){return b==0?a:gcd(b,a%b);}
signed main()
{
    // freopen("testdata.in","r",stdin);
    T=read();
    while(T--)
    {
        N=read(); M=read();
        int p=N*M;
        bool ck=0;
        for(int a=N;a>=1;a--)
        {
            if(gcd(a,N)!=1) continue;
            for(int b=M;b>=1;b--)
            {
                if(gcd(b,M)!=1) continue;
                if(gcd(a,b)!=1) continue;
                // cout << "a=" << a << ", b=" << b << '\n';
                for(int i=1;i<=N;i++) ar[i]=(1+(i-1)*a)%p;
                for(int i=1;i<=M;i++) br[i]=(1+(i-1)*b)%p;
                bool tag=0;
                for(int i=1;i<=N;i++)
                {
                    for(int j=1;j<=M;j++)
                    {
                        int now=(ar[i]*br[j])%p;
                        if(vis[now]) {tag=1; break;}
                        vis[now]=1;
                    }
                    if(tag) break;
                }
                if(!tag) {ck=1; break;}
                for(int i=0;i<=N*M;i++) vis[i]=0;
            }
            if(ck) break;
        }
        if(ck)
        {
            cout << "Yes\n";
            for(int i=1;i<=N;i++) cout << ar[i] << " "; cout << '\n';
            for(int i=1;i<=M;i++) cout << br[i] << " "; cout << '\n';
        }
        else cout << "No\n";
        for(int i=0;i<=N*M;i++) vis[i]=0;
    }
    return (0-0);
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 5684kb

input:

2
2 3
2 2

output:

Yes
1 2 
1 3 5 
No

result:

ok 2 cases (2 test cases)

Test #2:

score: 0
Accepted
time: 53ms
memory: 14172kb

input:

1
1 1000000

output:

Yes
1 
1 0 999999 999998 999997 999996 999995 999994 999993 999992 999991 999990 999989 999988 999987 999986 999985 999984 999983 999982 999981 999980 999979 999978 999977 999976 999975 999974 999973 999972 999971 999970 999969 999968 999967 999966 999965 999964 999963 999962 999961 999960 999959 99...

result:

ok 1 cases (1 test case)

Test #3:

score: 0
Accepted
time: 58ms
memory: 13776kb

input:

1
1000000 1

output:

Yes
1 0 999999 999998 999997 999996 999995 999994 999993 999992 999991 999990 999989 999988 999987 999986 999985 999984 999983 999982 999981 999980 999979 999978 999977 999976 999975 999974 999973 999972 999971 999970 999969 999968 999967 999966 999965 999964 999963 999962 999961 999960 999959 99995...

result:

ok 1 cases (1 test case)

Test #4:

score: -100
Time Limit Exceeded

input:

1
2 500000

output:


result: