답안 #441072

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
441072 2021-07-04T05:34:53 Z 8e7 Nice sequence (IZhO18_sequence) C++14
0 / 100
1 ms 332 KB
//Challenge: Accepted
#include <iostream>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
#include <utility>
#include <assert.h>
using namespace std;
void debug() {cout << endl;}
template <class T, class ...U> void debug(T a, U ... b) { cout << a << " "; debug(b...);}
template <class T> void pary(T l, T r) {
	while (l != r) {cout << *l << " ";l++;}
	cout << endl;
}
#define ll long long
#define ld long double
#define maxn 400005
#define mod 1000000007
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
int pref[maxn], deg[maxn];
bool vis[maxn];
int gcd(int a, int b) {
	if (a < b) swap(a, b);
	return b == 0 ? a : gcd(b, a % b);
}
int main() {
	io
	int t;
	cin >> t;
	while (t--) {
		int n, m, sw = 0;
		cin >> n >> m;
		if (n < m) swap(n, m), sw = 1;
		int siz = (m % n == 0 ? m : n + m - gcd(n, m));
		for (int i = 0;i < siz;i++) deg[i] = 0;
		int cnt = 0;
		queue<int> que;
		for (int i = 0;i < siz;i++) {
			if (i + n < siz) deg[i + n]++;
			if (i - m >= 0) deg[i - m]++;
		}
		for (int i = 0;i < siz;i++) {
			if (deg[i] == 0) que.push(i);
		}
		while (que.size()) {
			int cur = que.front();que.pop();
			pref[cur] = cnt++;
			if (cur + n < siz && --deg[cur + n] == 0) que.push(cur + n);
			if (cur - m >= 0 && --deg[cur - m] == 0) que.push(cur - m);
		}
		
		cout << siz - 1 << "\n";
		for (int i = 1;i < siz;i++) cout << pref[i] - pref[i - 1] << " ";
		cout << "\n";
	}
}

Compilation message

sequence.cpp: In function 'int main()':
sequence.cpp:37:13: warning: variable 'sw' set but not used [-Wunused-but-set-variable]
   37 |   int n, m, sw = 0;
      |             ^~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB there is incorrect sequence
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB there is incorrect sequence
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB there is incorrect sequence
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB there is incorrect sequence
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB there is incorrect sequence
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB there is incorrect sequence
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB there is incorrect sequence
2 Halted 0 ms 0 KB -