Submission #488602

#TimeUsernameProblemLanguageResultExecution timeMemory
488602keta_tsimakuridzeNice sequence (IZhO18_sequence)C++14
76 / 100
2070 ms33528 KiB
#include<bits/stdc++.h>
#define f first
#define s second
#define pii pair<int,int>
//#define int long long
using namespace std;
const int N = 4e5 + 5, mod = 1e9 + 7; // !
int t, in[N],n,m, p[N];
vector<int> V[N], v;
int check(int x) {
	for(int i = 0; i <= x; i++) in[i] = 0, V[i].clear();
	for(int i = 0; i <= x; i++) {
		if(i + n <= x) {
			in[i + n]++;
			V[i].push_back(i + n);
		}
		if(i + m <= x) {
			in[i]++;
			V[i + m].push_back(i);
		}
	}
	vector<int> q;
	for(int i = 0; i <= x; i++) {
		if(!in[i]) q.push_back(i);
	}	
	v.clear();
	while(q.size()) {
		int u = q.back();
		q.pop_back();
		v.push_back(u);
		for(int i = 0; i < V[u].size(); i++) {
			in[V[u][i]]--;
			if(!in[V[u][i]]) q.push_back(V[u][i]);
		}
	}
	return v.size();
}
main() {
//	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
//	#define endl " "
	//cin >> t;
	scanf("%d", &t);
	while(t--) {
		scanf("%d %d", &n, &m);
		int l = max(n, m), r = 400000, ans = max(n, m) - 1;
		while(l <= r) {
			int mid = (l + r)/2;
			if(check(mid) == mid + 1) {
				ans = mid, l = mid + 1;
			} else r = mid - 1;
		}

		printf("%d\n", ans);
		check(ans);
		reverse(v.begin(), v.end());
		for(int i = 0; i < v.size(); i++) {
			p[v[i]] = i + 1;
		}
		for(int i = 1; i <= ans; i++) {
			printf("%d ", p[i] - p[i - 1]);
		}
	}
}

Compilation message (stderr)

sequence.cpp: In function 'int check(int)':
sequence.cpp:31:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |   for(int i = 0; i < V[u].size(); i++) {
      |                  ~~^~~~~~~~~~~~~
sequence.cpp: At global scope:
sequence.cpp:38:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   38 | main() {
      | ^~~~
sequence.cpp: In function 'int main()':
sequence.cpp:56:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |   for(int i = 0; i < v.size(); i++) {
      |                  ~~^~~~~~~~~~
sequence.cpp:42:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |  scanf("%d", &t);
      |  ~~~~~^~~~~~~~~~
sequence.cpp:44:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |   scanf("%d %d", &n, &m);
      |   ~~~~~^~~~~~~~~~~~~~~~~
#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...