Submission #1116132

# Submission time Handle Problem Language Result Execution time Memory
1116132 2024-11-21T09:29:08 Z adiyer Nice sequence (IZhO18_sequence) C++17
0 / 100
4 ms 13136 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 4e5 + 11;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

ll n, m, pos;
ll a[N], was[N], ans[N];

vector < ll > ord, g[N];

bool cyc;

void dfs(ll v){
	was[v] = 1;
	for(ll u : g[v])
		if(!was[u])
			dfs(u);
	ord.push_back(v);
}

bool f(ll sz){
	cyc = 0, ord.clear();
	fill(was, was + sz + 1, 0);
	for(ll i = 0; i <= sz; i++){
		g[i].clear();
		if(i - n >= 0) g[i].push_back(i - n);
		if(i + m <= sz) g[i].push_back(i + m);
	}
	for(ll i = 0; i <= sz; i++)
		if(!was[i])
			dfs(i);
	reverse(ord.begin(), ord.end());
	fill(was, was + sz + 1, 0);
	for(ll v : ord){
		for(ll u : g[v]){
			if(was[u]){
				return 0;
			}
		}
	}
	return 1;
}

void solve(){
	cin >> n >> m;
	ll l = 0, r = n + m, val = 0;
	while(r - l > 1){
		ll md = (l + r) / 2;
		if(f(md)) l = md;
		else r = md;
	}
	fill(ans, ans + l + 1, 0), f(l - 1);
	for(ll i = 0; i < l; i++) ans[ord[i]] = i + 1;
	ll p = ans[0];
	cout << l - 1 << '\n';
	for(ll i = 1; i < l; i++) cout << ans[i] - p << ' ', p += ans[i] - p;
	cout << '\n';
}

signed main(){
	ll cs;
	cin >> cs;
	while(cs--){
		solve();
	}
}

Compilation message

sequence.cpp: In function 'void solve()':
sequence.cpp:51:23: warning: unused variable 'val' [-Wunused-variable]
   51 |  ll l = 0, r = n + m, val = 0;
      |                       ^~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12880 KB Ok
2 Incorrect 3 ms 12880 KB there is incorrect sequence
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 12880 KB there is incorrect sequence
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 13048 KB Ok
2 Correct 4 ms 13136 KB Ok
3 Incorrect 4 ms 12880 KB there is incorrect sequence
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 13056 KB there is incorrect sequence
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12880 KB Ok
2 Incorrect 3 ms 12880 KB there is incorrect sequence
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12880 KB Ok
2 Incorrect 3 ms 12880 KB there is incorrect sequence
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12880 KB Ok
2 Incorrect 3 ms 12880 KB there is incorrect sequence
3 Halted 0 ms 0 KB -