QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#783459#9799. Magical PaletteKleavesWA 45ms26852kbC++172.4kb2024-11-26 09:57:432024-11-26 09:57:45

Judging History

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

  • [2024-11-26 09:57:45]
  • 评测
  • 测评结果:WA
  • 用时:45ms
  • 内存:26852kb
  • [2024-11-26 09:57:43]
  • 提交

answer

#pragma GCC optimize(3)
#define _CRT_SECURE_NO_WARNINGS 1
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define testin freopen("testin1.txt", "r", stdin)
#define testout freopen("testout1.txt", "w", stdout)
#define NO cout<<"No"<<endl
#define YES cout<<"Yes"<<endl
#define MAYBE cout<<"MAYBE"<<endl
#define endl '\n'
#define ALL(x) x.begin(),x.end()
#define INS(x)inserter(x,x.begin())
using namespace std;
const ll MAXN = 1000010;
const ll INF = 0x3f3f3f3f;
const ll mod = 998244353;
bool DEBUG = true;
vector<ll>numn,numm;
ll uniq[MAXN][2];
void solve() {
	ll n, m;
	cin >> n >> m;
	if (gcd(n, m) != 1) {
		cout << "No" << endl;
		return;
	}
	cout << "Yes" << endl;
	for (int i = 0; i < n; i++) {
		//cout << (1 + (n - 1) * i) % (n * m) << ' ';
	}
	//cout << endl;
	for (int i = 0; i < m; i++) {
		//cout << (1 + (m - 1) * i) % (n * m) << ' ';
	}
	//cout << endl;
	ll flag = 1;
	for (ll d1 = max(n - 1, 1ll); d1 >= 1; d1--) {
		for (ll d2 = max(m - 1, 1ll); d2 >= 1; d2--) {
			flag = 1;
			numn.clear();
			numm.clear();
			for (ll i = 0; i < n; i++) {
				numn.push_back((1 + d1 * i) % (n * m));
			}
			for (ll i = 0; i < m; i++) {
				numm.push_back((1 + d2 * i) % (n * m));
			}
			//map<ll, pair<ll, ll>>uniq;
			for (int i = 0; i < m * n; i++) {
				uniq[i][0] = -1; uniq[i][1] = -1;
			}
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < m; j++) {
					ll tmp = (numn[i] * numm[j]) % (m * n);
					if (uniq[tmp][0] != -1) {
						if (DEBUG) {
							cout << "ERROR:" << tmp << endl;
							ll fst = uniq[tmp][0];
							ll snd = uniq[tmp][1];
							cout << "FIRST:" << fst + 1 << "," << snd + 1 << endl;
							cout << "SECOND:" << i + 1 << "," << j + 1 << endl;
						}
						flag = 0;
						break;
					}
					else {
						uniq[tmp][0] = i;
						uniq[tmp][1] = j;
					}
				}
				if (flag == 0)break;
			}
			if (flag == 1) {
				for (int i = 0; i < n; i++) {
					cout << (1 + d1 * i) % (n * m) << ' ';
				}
				cout << endl;
				for (int i = 0; i < m; i++) {
					cout << (1 + d2 * i) % (n * m) << ' ';
				}
				cout << endl;
				return;
			}
		}
	}
	return;
}
int main() {
	//testin;
	//freopen("case1out.txt", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	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: 3580kb

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: 37ms
memory: 26640kb

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: 45ms
memory: 26852kb

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: 0
Accepted
time: 0ms
memory: 3580kb

input:

1
2 500000

output:

No

result:

ok 1 cases (1 test case)

Test #5:

score: 0
Accepted
time: 25ms
memory: 22792kb

input:

1
2 499999

output:

Yes
1 2 
1 499999 999997 499997 999995 499995 999993 499993 999991 499991 999989 499989 999987 499987 999985 499985 999983 499983 999981 499981 999979 499979 999977 499977 999975 499975 999973 499973 999971 499971 999969 499969 999967 499967 999965 499965 999963 499963 999961 499961 999959 499959 99...

result:

ok 1 cases (1 test case)

Test #6:

score: 0
Accepted
time: 0ms
memory: 3552kb

input:

1
500000 2

output:

No

result:

ok 1 cases (1 test case)

Test #7:

score: 0
Accepted
time: 24ms
memory: 23084kb

input:

1
499999 2

output:

Yes
1 499999 999997 499997 999995 499995 999993 499993 999991 499991 999989 499989 999987 499987 999985 499985 999983 499983 999981 499981 999979 499979 999977 499977 999975 499975 999973 499973 999971 499971 999969 499969 999967 499967 999965 499965 999963 499963 999961 499961 999959 499959 999957 ...

result:

ok 1 cases (1 test case)

Test #8:

score: 0
Accepted
time: 0ms
memory: 3688kb

input:

1
3 333333

output:

No

result:

ok 1 cases (1 test case)

Test #9:

score: -100
Wrong Answer
time: 30ms
memory: 22024kb

input:

1
3 333332

output:

Yes
ERROR:666663
FIRST:1,3
SECOND:2,111113
ERROR:1
FIRST:1,1
SECOND:1,166667
ERROR:333330
FIRST:1,2
SECOND:2,185186
ERROR:1
FIRST:1,1
SECOND:1,250000
1 3 5 
1 333328 666655 999982 333313 666640 999967 333298 666625 999952 333283 666610 999937 333268 666595 999922 333253 666580 999907 333238 666565 9...

result:

wrong output format Expected integer, but "ERROR:666663" found (test case 1)