CSES - Putka Open 2015 – 1/6 - Results
Submission details
Task:Aita
Sender:
Submission time:2015-07-18 18:08:36 +0300
Language:C++
Status:COMPILE ERROR

Compiler report

g++: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-4.9/README.Bugs> for instructions.

Code

#include <iostream>
#include <cmath>
#include <set>
#include <algorithm>
#include <deque>

#define ll long long
#define ull unsigned long long

#define pii pair<int, int>
#define pll pair<long long, long long>

#define defmod 1000000007
using namespace std;


int main(){
	cin.sync_with_stdio(0);
	cin.tie(0);
	
	ll n, k; cin >> n >> k;
	if(n <= 10){
		deque<int> heh;
		for(int i = 0; i < n; i++)
			heh.push_back(i+1);
		do{
			bool okkkkk = true;
			for(int i = 1; i < n; i++){
				if(abs(heh[i]-heh[i-1]) < k)
					okkkkk = false;
			}

			if(okkkkk){
				for(int i = 0; i < n; i++){
					cout << heh[i] << " ";
				}
				cout << endl;
				return 0;
			}
			
		}while(next_permutation(heh.begin(), heh.end()));
		cout << "QAQ" << endl;
	}
	ll r[101010] = {0};
	set<int> lo;
	for(int i = 0; i < n; i++)
		lo.insert(i+1);
	r[1] = 1;
	lo.erase(1);
	for(int i = 2; i <= n; i++){
		if(lo.count(r[i-1]+k)){
			r[i] = r[i-1]+k;
			lo.erase(r[i]);
		}
		else if(lo.count(r[i-1]-k)){
			r[i] = r[i-1]-k;
			lo.erase(r[i]);
		}
		else{
			int nn = *(lo.begin());
			if(abs(r[i-1]-nn) < k){
				nn = *(lo.lower_bound(r[i-1]+k));
				if(lo.count(nn) && abs(r[i-1]-nn) >= k){
					r[i] = nn;
					lo.erase(nn);
				}

			}
			else{
				r[i] = nn;
				lo.erase(nn);
			}
		}

	}

	r[0] = 99999999999LL;
	r[n+1] = 999999999999LL;
	for(int i = 1; i <= n; i++){
		if(abs(r[i]-r[i+1]) < k || abs(r[i]-r[i-1]) < k || r[i] <= 0 || r[i] > n){
			cout << "QAQ" << endl;
			return 0;
		}
	}
	for(int i = 1; i <= n; i++){
		cout << r[i] << " ";
	}
	cout << endl;
	return 0;
}