CSES - Datatähti Open 2021 - Results
Submission details
Task:Split in Three
Sender:wabadaba
Submission time:2021-01-31 18:22:25 +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

Code

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;

// change ld to db if neccesary
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pld;

typedef set<int> si;
typedef set<ll> sl;
typedef set<ld> sld;
typedef set<str> ss;
typedef set<pi> spi;
typedef set<pl> spl;
typedef set<pld> spld;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ld> vld;
typedef vector<str> vs;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<si> vsi;
typedef vector<sl> vsl;
typedef vector<pld> vpld;

#define mp make_pair
#define f first
#define s second
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound

#define forr(i,a,b) for (int i = (a); i < (b); i++)
#define ford(i,a,b) for (int i = (a)-1; i >= (b); i--)
#define trav(a,x) for (auto& a: x)

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
int pct(int x) { return __builtin_popcount(x); }
int bits(int x) { return 31-__builtin_clz(x); } // floor(log2(x))
int fstTrue(function<bool(int)> f, int lo, int hi) {
	hi ++; assert(lo <= hi); // assuming f is increasing
	while (lo < hi) { // find first index such that f is true
		int mid = (lo+hi)/2;
		f(mid) ? hi = mid : lo = mid+1;
	}
	return lo;
}

const ll MOD = 1e9+7;
const int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1}, dy[8] = {0, 1, 0, -1, -1, 1, -1, 1};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
ll binpow(ll a,ll b){ll res=1;while(b){if(b&1)res=(res*a)%MOD;a=(a*a)%MOD;b>>=1;}return res;}
ll modInv(ll a){return binpow(a, MOD-2);}
bool sortcol(const vl& v1, const vl& v2) {return v1[1] < v2[1];}
bool sortpair(const pi& p1, const pi& p2) {return p1.f < p2.f;}

mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
uniform_int_distribution<long long unsigned> distribution(0,10);

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
// void __print(mi x) {cerr << x;}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif

const int mxN = 2e5+5;
int n, ans[105];
array<int,3> curr;

void solve() {
	cin >> n;
	if ((n*(n+1)/2) % 3) cout << "IMPOSSIBLE\n";
	else if (n == 3) cout << "1 2 3\n";
	else {
		int mid = (n*(n+1)/2)/3;
		// ford(i,n+1,1) {
		// 	if (curr[2] + i <= mid+1) {
		// 		curr[2] += i;
		// 		ans[i] = 3;
		// 	} else if (curr[1] + i <= mid) {
		// 		curr[1] += i;
		// 		ans[i] = 2;
		// 	} else {
		// 		curr[0] += i;
		// 		ans[i] = 1;
		// 	}
		// }
		// if (curr[0]+1 == curr[1] && curr[1]+1 == curr[2]) {
		// 	forr(i,1,n+1) cout << ans[i] << " \n"[i==n];
		// } else cout << "IMPOSSIBLE\n";
		// assert(curr[0]+1 == curr[1] && curr[1]+1 == curr[2]);
		// forr(i,1,n+1) cout << ans[i] << " \n"[i==n];
		int one = 0;
		ford(i,n+1,1) {
			if (curr[2] + i <= mid) {
				curr[2] += i;
				ans[i] = 3;
				if (i == 1) one = 3;
			} else if (curr[1] + i <= mid) {
				curr[1] += i;
				ans[i] = 2;
				if (i == 1) one = 2;
			} else {
				curr[0] += i;
				ans[i] = 1;
				if (i == 1) one = 1;
			}
		}
		assert(curr[0] == curr[1] && curr[1] == curr[2]);
		if (one == 1) {
			ans[1] = 3;
			forr(i,1,n+1) cout << ans[i] << " \n"[i==n];
		} else if (one == 2) {
			ans[1] = 3;
			forr(i,1,n+1) {
				if (ans[i] == 1) ans[i] = 2;
				else if (ans[i] == 2) ans[i] = 1;
			}
			forr(i,1,n+1) cout << ans[i] << " \n"[i==n];
		} else {
			ans[1] = 1;
			forr(i,1,n+1) {
				if (ans[i] == 1) ans[i] = 3;
				else if (ans[i] == 3) ans[i] = 1;
			}
			forr(i,1,n+1) cout << ans[i] << " \n"[i==n];
		}
	}
}

int main() {
	cin.tie(0)->sync_with_stdio(0);
	// freopen(".in", "r", stdin);
	// freopen(".out", "w", stdout);

	int tc = 1;
	// cin >> tc;
	while (tc--) solve();
}

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 2 2 1 3

Test 4

Group: 1, 2

Verdict: ACCEPTED

input
6

correct output
1 3 2 2 1 3 

user output
3 2 3 3 2 1

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
3 1 1 3 2 1 2 3

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 3 2 2 3

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
3 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
3 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
3 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
3 1 1 1 1 3 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
3 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