제출 #1132671

#제출 시각아이디문제언어결과실행 시간메모리
1132671Halym2007Nice sequence (IZhO18_sequence)C++17
6 / 100
0 ms328 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define sz size()
#define ff first
#define ss second
#define pb push_back
#define pii pair <int, int>
#define dur exit(0)
#define dur1 return(0)
const int N = 2e5 + 5;
int jog[N], n, m;
ll p[N];

int valid (int x) {
	for (int i = 1; i <= x; ++i) {
		p[i] = p[i - 1] + jog[i];
	}
	int ret = 1;
	for (int i = 1; i <= x; ++i) {
		if (i + m - 1 <= x) {
			ll kk = p[i + m - 1] - p[i - 1];
			if (kk < 1) {
				ret &= 0;
			}
		}
		if (i + n - 1 <= x) {
			ll kk = p[i + n - 1] - p[i - 1];
			if (kk > -1) {
				ret &= 0;
			}
		}
	}
	return 1;
}

int main () {
//	freopen ("input.txt", "r", stdin);
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t;
	cin >> t;
	while ( t-- ) {
		cin >> n >> m;
		if (n % m == 0 or m % n == 0) {
			int x = (n > m ? 1 : -1);
			cout << max (n, m) - 1 << "\n";
			for (int i = 1; i <= max (n, m) - 1; ++i) {
				cout << x << " ";
			}
			cout << "\n";
		}
		else {
			int git;			
			if (n > m) {
				int x1 = -n;
				int x2 = (m - 1) * n + 1;
				git = n;
				while ((git + 1) % m) {
					git++;
				}
				cout << git << "\n";
				for (int i = 1; i <= git; ++i) {
					if (i % m == 0) jog[i] = x2;
					else jog[i] = x1;
				}
			}
			else {
				int x1 = m;
				int x2 = (n - 1) * m + 1;
				x2 *= (-1);
			 	git = m;
				while ((git + 1) % n) {
					git++;
				}
				cout << git << "\n";
				for (int i = 1; i <= git; ++i) {
					if (i % n == 0)	jog[i] = x2;
					else jog[i] = x1;
				}
			}
			assert (valid(git) == 1);
			cout << git << "\n";
			for (int i = 1; i <= git; ++i) {
				cout << jog[i] << " ";
			}
			cout << "\n";
		}
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...