QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#783452#9799. Magical PaletteKleavesTL 45ms26976kbC++172.3kb2024-11-26 09:55:032024-11-26 09:55:03

Judging History

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

  • [2024-11-26 09:55:03]
  • 评测
  • 测评结果:TL
  • 用时:45ms
  • 内存:26976kb
  • [2024-11-26 09:55:03]
  • 提交

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 = false;
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 = n; d1 >= 1; d1--) {
		for (ll d2 = m; 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: 3640kb

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: 44ms
memory: 26748kb

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: 26976kb

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: 3640kb

input:

1
2 500000

output:

No

result:

ok 1 cases (1 test case)

Test #5:

score: -100
Time Limit Exceeded

input:

1
2 499999

output:


result: