Submission #507124

# Submission time Handle Problem Language Result Execution time Memory
507124 2022-01-12T09:03:42 Z Mazaalai Nice sequence (IZhO18_sequence) C++17
0 / 100
3 ms 332 KB
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
int n, m, mul = -11;
const int N = 2e5 + 5;
int arr[2*N];
bool vis[2*N];
void go() {
	mul = -1;
	cin >> n >> m;
	for (int i = 0; i <= m*2; i++) {
		vis[i] = 0;
		arr[i] = 0;
	}
	if (m < n) {
		swap(n, m);
		mul = 1;
	}
	if (m % n == 0) {
		cout << m-1 << '\n';
		for (int i = 1; i < m; i++) 
			cout << 1 * mul << " \n"[i==m-1];
		return;
	}
	if (n == 2) {
		cout << m << '\n';
		for (int i = 1; i <= m; i++) 
			cout << (i & 1 ? -n : n+1) * mul << " \n"[i==m];
		return;
	}
	int i = 0, j = (m)%n, smol = (m-1)%n;
	vector <int> pos;
	while(1) {
		if (!vis[i]) {
			vis[i] = 1;
			pos.pb(i);
			i = (i + 1) % n;
		}
		if (!vis[j]) {
			vis[j] = 1;
			pos.pb(j);
			j = (j + 1) % n;
		}
		if (i == n-1) break;
	}
	int lst = 0;
	for (i = 0; i < n; i++) 
		if (pos[i] <= smol) lst = i;
	int Y = pos[lst]; // 0->x, 1->y
	Y = (Y+1)%n;
	int a, b, c = m / n + 1, d, x, y;
	a = n-1, b = 1;
	d = c+1, c = m - d;
	x = 10 * d;
	y = 10 * a * d - 1;

	lst = 1;
	while(1) {
		int curNum = (lst%n == Y) ? -y : x;
		// cout << lst << ' ' << curNum << '\n';
		arr[lst] = arr[lst-1] + curNum;
		if (lst >= n) {
			int tmp = arr[lst] - (lst-n >= 0 ? arr[lst-n] : 0);
			if (tmp <= 0) {
				// cout << tmp << ' ';
				// cout << "ERR: n\n";
				break;
			}
		}
		if (lst >= m) {
			int tmp = arr[lst] - (lst-m >= 0 ? arr[lst-m] : 0);
			if (tmp >= 0) {
				// cout << tmp << ' ';
				// cout << "ERR: m\n";
				break;
			}
		}
		lst++;
		// pos.pb(curNum);
		// cout << curNum << ' ';
	}
	cout << lst-1 << '\n';
	for (int i = 1; i < lst; i++) cout << arr[i]-arr[i-1] << " \n"[i==lst-1];
}
signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
	int T;
	cin >> T;
	while(T--) go();
}

Compilation message

sequence.cpp: In function 'void go()':
sequence.cpp:51:9: warning: variable 'b' set but not used [-Wunused-but-set-variable]
   51 |  int a, b, c = m / n + 1, d, x, y;
      |         ^
sequence.cpp: In function 'int main()':
sequence.cpp:89:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   89 |  freopen("in.txt", "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
sequence.cpp:90:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   90 |  freopen("out.txt", "w", stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 332 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 332 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 332 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 332 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 332 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 332 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 332 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -