CSES - Putka Open 2015 – 1/6 - Results
Submission details
Task:Aita
Sender:
Submission time:2015-07-18 16:58:58 +0300
Language:C++
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#1ACCEPTED0.08 s1details
#2ACCEPTED0.08 s1details
#30.08 s1details
#4ACCEPTED0.09 s1details
#50.08 s1details
#6ACCEPTED0.09 s2details
#7ACCEPTED0.09 s2details
#8ACCEPTED0.09 s2details
#9ACCEPTED0.08 s2details
#100.09 s2details
#11ACCEPTED0.11 s3details
#12ACCEPTED0.11 s3details
#13--3details
#14--3details
#15--3details

Code

#include <iostream>
#include <cmath>

#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;
	ll re[101010];
	ll pos[101010] = {0};
	for(int i = 0; i < n; i++){
		re[i+1] = i+1;
		pos[i+1] = i+1;
	}

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

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

			}
			else{
				if(i == 1){
					if(abs(re[i]-re[i+1]) < k)
					ok2 = false;
				}
				else if(i == n){
					if(abs(re[i]-re[i-1]) < k)
						ok2 = false;
				}
				else{
					if(abs(re[i]-re[i+1]) < k)
						ok2 = false;
					if(abs(re[i]-re[i-1]) < k)
						ok2 = false;
				}	
			}
			if(ok2){
				//for(int i = 1; i <= n; i++){
				//	cout << re[i] << " ";
				//}
				//cout << endl << "on ok" << endl;
				goto out;
			}
				
			else{
				swap(re[j], re[i]);
				swap(pos[re[i]], pos[re[j]]);
				//for(int i = 1; i <= n; i++){
				//	cout << re[i] << " ";
				//}
				//cout << endl << "ei ollut ok" << endl;
			}
		}
		for(int kk = re[i]+k; kk <= n; kk++){
			int j = pos[kk];
			if(j == i)
				continue;
			bool ok2 = true;
			swap(re[i], re[j]);
			swap(pos[re[i]], pos[re[j]]);
			if(j < i){
				if(i == 1){
					if(abs(re[i]-re[i+1]) < k)
					ok2 = false;
				}
				else if(i == n){
					if(abs(re[i]-re[i-1]) < k)
						ok2 = false;
				}
				else{
					if(abs(re[i]-re[i+1]) < k)
						ok2 = false;
					if(abs(re[i]-re[i-1]) < k)
						ok2 = false;
				}
				if(j == 1){
					if(abs(re[j]-re[j+1]) < k)
					ok2 = false;
				}
				else if(j == n){
					if(abs(re[j]-re[j-1]) < k)
						ok2 = false;
				}
				else{
					if(abs(re[j]-re[j+1]) < k)
						ok2 = false;
					if(abs(re[j]-re[j-1]) < k)
						ok2 = false;
				}	

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

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

Test details

Test 1

Group: 1

Verdict: ACCEPTED

input
2 2

correct output
QAQ

user output
QAQ

Test 2

Group: 1

Verdict: ACCEPTED

input
3 2

correct output
QAQ

user output
QAQ

Test 3

Group: 1

Verdict:

input
4 2

correct output
3 1 4 2 

user output
QAQ

Test 4

Group: 1

Verdict: ACCEPTED

input
7 4

correct output
QAQ

user output
QAQ

Test 5

Group: 1

Verdict:

input
8 4

correct output
5 1 6 2 7 3 8 4 

user output
QAQ

Test 6

Group: 2

Verdict: ACCEPTED

input
80476 2

correct output
40239 1 40240 2 40241 3 40242 ...

user output
8 6 11 9 5 7 2 14 10 12 17 13 ...

Test 7

Group: 2

Verdict: ACCEPTED

input
68652 2

correct output
34327 1 34328 2 34329 3 34330 ...

user output
8 6 11 9 5 7 2 14 10 12 17 13 ...

Test 8

Group: 2

Verdict: ACCEPTED

input
62735 2

correct output
31368 1 31369 2 31370 3 31371 ...

user output
8 6 11 9 5 7 2 14 10 12 17 13 ...

Test 9

Group: 2

Verdict: ACCEPTED

input
71954 2

correct output
35978 1 35979 2 35980 3 35981 ...

user output
8 6 11 9 5 7 2 14 10 12 17 13 ...

Test 10

Group: 2

Verdict:

input
4 2

correct output
3 1 4 2 

user output
QAQ

Test 11

Group: 3

Verdict: ACCEPTED

input
89814 3

correct output
44908 1 44909 2 44910 3 44911 ...

user output
16 32 11 22 14 10 13 17 9 19 1...

Test 12

Group: 3

Verdict: ACCEPTED

input
91140 5

correct output
45571 1 45572 2 45573 3 45574 ...

user output
21 39 17 10 15 29 19 14 9 4 31...

Test 13

Group: 3

Verdict:

input
66703 16675

correct output
33352 1 33353 2 33354 3 33355 ...

user output
(empty)

Test 14

Group: 3

Verdict:

input
66666 33333

correct output
33334 1 33335 2 33336 3 33337 ...

user output
(empty)

Test 15

Group: 3

Verdict:

input
66666 33334

correct output
QAQ

user output
(empty)