Submission #341739

# Submission time Handle Problem Language Result Execution time Memory
341739 2020-12-30T20:20:29 Z Tosic Nice sequence (IZhO18_sequence) C++14
9 / 100
2000 ms 17064 KB
#include <bits/stdc++.h>
#define maxn 100010
using namespace std;

int n, m, t, prefS[maxn], ans;
vector<int> topV, was,res;

void topSort(int x, int mx){
	// prefS[x+n] < prefS[x], prefS[x-m] < prefS[x]
	was[x] = 1;
	if(x+n <= mx and !was[x+n]){
		topSort(x+n, mx);
	}
	if(x-m >= 0 and !was[x-m]){
		topSort(x-m, mx);
	}
	topV.push_back(x);
}

bool ok(int mx){
	topV.clear();
	was.clear();
	res.clear();
	was.resize(maxn+2, 0);
	//cerr << mx << ' ' << n << ' ' << m << '\n';
	for(int i = 0; i <= mx; ++i){
		//cerr << was[i] << ' ';
		if(!was[i]){
			topSort(i, mx);
		}
	}
	for(int i = 0; i <= mx; ++i){
		prefS[topV[i]] = i;
	}
	for(int i = 0; i <= mx; ++i){
		if( (i+n<=mx and prefS[i] < prefS[i+n]) or (i-m >= 0 and prefS[i-m] > prefS[i]) ){
			return 0;
		}
	}
	for(int i = 1 ;i <mx+1;++i){
		res.push_back(prefS[i]-prefS[i-1]);
	}
	return 1;
}

int main(){
	ios_base::sync_with_stdio(0);
	cout.tie(0);
	cin.tie(0);
	cin >> t;
	while(t--){
		cin >> n >> m;
		int l = 0, r = maxn;
		while(l <= r){
			int mid = (l+r)/2;
			//cerr<<mid<<'\n';
			if(ok(mid)){
				l=mid+1;
				ans = max(ans, mid);
			} else {
				r = mid-1;
			}
		}
		ok(ans);
		cout << res.size()<<'\n';
		for(auto i:res){
			cout << i << ' ';
		}
		cout << '\n';
	}
}
# Verdict Execution time Memory Grader output
1 Correct 30 ms 4336 KB Ok
2 Incorrect 21 ms 4464 KB Jury has the better answer : jans = 59, pans = 0
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 23 ms 2800 KB Ok
2 Correct 27 ms 2800 KB Ok
3 Correct 24 ms 3056 KB Ok
4 Correct 23 ms 2800 KB Ok
5 Correct 23 ms 2800 KB Ok
6 Correct 28 ms 2928 KB Ok
7 Correct 49 ms 3568 KB Ok
8 Correct 35 ms 3184 KB Ok
9 Correct 53 ms 3568 KB Ok
10 Correct 40 ms 3260 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 10 ms 4336 KB Ok
2 Incorrect 27 ms 4464 KB Jury has the better answer : jans = 4, pans = 0
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 23 ms 2800 KB Ok
2 Correct 24 ms 1648 KB Ok
3 Correct 22 ms 1520 KB Ok
4 Correct 24 ms 1392 KB Ok
5 Correct 22 ms 1392 KB Ok
6 Execution timed out 2077 ms 17064 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 30 ms 4336 KB Ok
2 Incorrect 21 ms 4464 KB Jury has the better answer : jans = 59, pans = 0
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 30 ms 4336 KB Ok
2 Incorrect 21 ms 4464 KB Jury has the better answer : jans = 59, pans = 0
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 30 ms 4336 KB Ok
2 Incorrect 21 ms 4464 KB Jury has the better answer : jans = 59, pans = 0
3 Halted 0 ms 0 KB -