CSES - Datatähti Open 2021 - Results
Submission details
Task:Split in Three
Sender:Black_hat
Submission time:2021-01-30 08:33:12 +0200
Language:C++ (C++17)
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED22
#2ACCEPTED78
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2details
#2ACCEPTED0.01 s1, 2details
#3ACCEPTED0.01 s1, 2details
#4ACCEPTED0.01 s1, 2details
#5ACCEPTED0.01 s1, 2details
#6ACCEPTED0.01 s1, 2details
#7ACCEPTED0.01 s1, 2details
#8ACCEPTED0.01 s1, 2details
#9ACCEPTED0.01 s2details
#10ACCEPTED0.01 s2details
#11ACCEPTED0.01 s2details
#12ACCEPTED0.01 s2details
#13ACCEPTED0.01 s2details
#14ACCEPTED0.01 s2details
#15ACCEPTED0.01 s2details

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:32:7: warning: unused variable 'j' [-Wunused-variable]
  ll i,j,k,l,n;
       ^
input/code.cpp:32:11: warning: unused variable 'l' [-Wunused-variable]
  ll i,j,k,l,n;
           ^

Code

#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define takeline cin.ignore();
#define iactive cout.flush();
#define N 100005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//----------------------------------------------
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
//	s-1 s s+1
//	3*s=(n*(n+1))/2;
	
	ll i,j,k,l,n;
	cin>>n;
	ll an[n+1];
	for(i=1;i<=n;i++){
		an[i]=3;
	}
	k=(n*(n+1))/2;
	if(k%3==0){
		ll s=k/3;
		ll fl[n+1]={0},cur_s=s;
//		cout<<s<<endl;
		for(i=n;i>=1&&cur_s>0;i--){
			if(i>cur_s){
				fl[cur_s]=1; an[cur_s]=2; break;
			}
			else{
				cur_s-=i; fl[i]=1; an[i]=2;
			}
		} cur_s=s-1;
		while(i>=1&&cur_s>0){
			if(i>cur_s){
				if(fl[cur_s]){i--; continue;
				}
				fl[cur_s]=1; an[cur_s]=1; break;
			}
			else{
				if(fl[i]){ i--; continue;
				}
				cur_s-=i; fl[i]=1; an[i]=1;
			}
			i--;
		}
		if(cur_s>0){
			for(i=1;i<=n;i++){
				if(an[i]==3) an[i]=1;
				if(an[i]!=2) fl[i]=0;
			}
			i=n; cur_s=s+1;
			while(i>=1){
				if(i>cur_s){
					if(fl[cur_s]){i--; continue;
					}
					fl[cur_s]=1; an[cur_s]=3; break;
				}
				else{
					if(fl[i]){ i--; continue;
					}
					cur_s-=i; fl[i]=1; an[i]=3;
				}
				i--;
			}
		}
		for(i=1;i<=n;i++){
			cout<<an[i]<<" ";
		}
	}
	else{
		cout<<"IMPOSSIBLE"<<endl;
	}
	return 0;
}

Test details

Test 1

Group: 1, 2

Verdict: ACCEPTED

input
3

correct output
1 2 3 

user output
1 2 3 

Test 2

Group: 1, 2

Verdict: ACCEPTED

input
4

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

Test 3

Group: 1, 2

Verdict: ACCEPTED

input
5

correct output
1 3 1 3 2 

user output
3 3 3 1 2 

Test 4

Group: 1, 2

Verdict: ACCEPTED

input
6

correct output
1 3 2 2 1 3 

user output
2 1 3 1 3 2 

Test 5

Group: 1, 2

Verdict: ACCEPTED

input
7

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

Test 6

Group: 1, 2

Verdict: ACCEPTED

input
8

correct output
2 3 1 2 3 3 2 1 

user output
1 1 1 2 1 3 3 2 

Test 7

Group: 1, 2

Verdict: ACCEPTED

input
9

correct output
1 2 3 1 2 3 3 2 1 

user output
3 1 1 1 1 2 3 3 2 

Test 8

Group: 1, 2

Verdict: ACCEPTED

input
10

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

Test 9

Group: 2

Verdict: ACCEPTED

input
42

correct output
1 3 2 2 1 3 1 2 3 3 2 1 1 2 3 ...

user output
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

Test 10

Group: 2

Verdict: ACCEPTED

input
95

correct output
1 3 1 3 2 1 2 3 3 2 1 1 2 3 3 ...

user output
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
Truncated

Test 11

Group: 2

Verdict: ACCEPTED

input
96

correct output
1 3 2 2 1 3 1 2 3 3 2 1 1 2 3 ...

user output
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
Truncated

Test 12

Group: 2

Verdict: ACCEPTED

input
97

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

Test 13

Group: 2

Verdict: ACCEPTED

input
98

correct output
2 3 1 2 3 3 2 1 1 2 3 3 2 1 1 ...

user output
1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 ...
Truncated

Test 14

Group: 2

Verdict: ACCEPTED

input
99

correct output
1 2 3 1 2 3 3 2 1 1 2 3 3 2 1 ...

user output
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
Truncated

Test 15

Group: 2

Verdict: ACCEPTED

input
100

correct output
IMPOSSIBLE

user output
IMPOSSIBLE