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

Compiler report

input/code.cpp:1:19: fatal error: iostram: No such file or directory
 #include <iostram>
                   ^
compilation terminated.

Code

#include <iostram>
#include <cmath>
#include <set>
#include <algorithm>
#include <vector>

#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){
		vector<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);
			}
		}

	}
	bool ebin = true;
	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){
			ebin = false;
		}
	}
	if(ebin){
		for(int i = 1; i <= n; i++){
			cout << r[i] << " ";
		}
		cout << endl;
		return 0;
	}

	for(int i = 0; i < n; i++){
		r[i+1] = i+1;
	}

	for(int i = 1; i <= n; i++){
		bool ok = true;
		if(i == 1){
			if(abs(r[i]-r[i+1]) < k)
				ok = false;
		}
		else if(i == n){
			if(abs(r[i]-r[i-1]) < k)
				ok = false;
		}
		else{
			if(abs(r[i]-r[i+1]) < k)
				ok = false;
			if(abs(r[i]-r[i-1]) < k)
				ok = false;
		}
		if(ok)
			continue;

		for(int j = n; j >= 1; j--){
			if(j == i)
				continue;
			bool ok2 = true;
			swap(r[i], r[j]);
			if(j < i){
				if(i == 1){
					if(abs(r[i]-r[i+1]) < k)
					ok2 = false;
				}
				else if(i == n){
					if(abs(r[i]-r[i-1]) < k)
						ok2 = false;
				}
				else{
					if(abs(r[i]-r[i+1]) < k)
						ok2 = false;
					if(abs(r[i]-r[i-1]) < k)
						ok2 = false;
				}
				if(j == 1){
					if(abs(r[j]-r[j+1]) < k)
					ok2 = false;
				}
				else if(j == n){
					if(abs(r[j]-r[j-1]) < k)
						ok2 = false;
				}
				else{
					if(abs(r[j]-r[j+1]) < k)
						ok2 = false;
					if(abs(r[j]-r[j-1]) < k)
						ok2 = false;
				}	

			}
			else{
				if(i == 1){
					if(abs(r[i]-r[i+1]) < k)
					ok2 = false;
				}
				else if(i == n){
					if(abs(r[i]-r[i-1]) < k)
						ok2 = false;
				}
				else{
					if(abs(r[i]-r[i+1]) < k)
						ok2 = false;
					if(abs(r[i]-r[i-1]) < k)
						ok2 = false;
				}	
			}
			if(ok2){
				//for(int i = 1; i <= n; i++){
				//	cout << r[i] << " ";
				//}
				//cout << endl << "on ok" << endl;
				brak;
			}
				
			else{
				swap(r[j], r[i]);
				//for(int i = 1; i <= n; i++){
				//	cout << r[i] << " ";
				//}
				//cout << endl << "ei ollut ok" << endl;
			}
		}

	}
	
	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){
			cout << "QAQ" << endl;
			return 0;
		}
	}
	for(int i = 1; i <= n; i++){
		cout << r[i] << " ";
	}
	cout << endl;
	return 0;
}