CSES - Datatähti Open 2021 - Results
Submission details
Task:Split in Three
Sender:rishb369
Submission time:2021-01-30 18:19:50 +0200
Language:C++ (C++11)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2details
#20.01 s1, 2details
#3ACCEPTED0.01 s1, 2details
#4ACCEPTED0.01 s1, 2details
#50.01 s1, 2details
#6ACCEPTED0.01 s1, 2details
#7ACCEPTED0.01 s1, 2details
#80.02 s1, 2details
#9ACCEPTED0.02 s2details
#10--2details
#11--2details
#12--2details
#13--2details
#14--2details
#15--2details

Compiler report

input/code.cpp: In function 'void usaco(std::__cxx11::string)':
input/code.cpp:12:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen((s+".in").c_str(), "r", stdin);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
input/code.cpp:13:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen((s+".out").c_str(), "w", stdout);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Code

#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;

void usaco(string s){
  freopen((s+".in").c_str(), "r", stdin);
  freopen((s+".out").c_str(), "w", stdout);
}

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);
#ifdef LOCAL_DEFINE
	freopen("input.txt", "r", stdin);
#endif
  int n; cin >> n;
  vector<int> v, ans(n, 0);
  for(int i = 1; i <= n; i++) v.push_back(i);
  int tot =  (n*(n+1))/2;
  int sum1 = tot/3 - 1, sum2 = tot/3, sum3 = tot/3 + 1, done = 0;
  //cout << tot << ' ' << sum1 << ' ' << sum2 << ' ' << sum3 << '\n';
  do{
  	int s1=0,s2=0,s3=0;// done=0;
  	done = 0;
  	for(int i = 0; i < n; i++){
  	  if(s1!=sum1){
  	    s1 += v[i];
  	    ans[v[i]-1] = 1;
  	  }
  	  else if(s2!=sum2){
  	    s2 += v[i];
  	    ans[v[i]-1] = 2;
  	  }
  	  else if(s3!=sum3){
  	    s3 += v[i];
  	    ans[v[i]-1] = 3;
  	  }
  	  
  	  if(s3 == sum3 and i == n-1){
  	    done = 1;
  	  }
  	}
  	if(done){
  	  for(auto i: ans) cout << i << ' ';
  	  cout << '\n';
  	  break;
  	}
  }
  while(next_permutation(all(v)));
  if(!done or sum1+sum2+sum3!=tot or n<5){
    cout << "IMPOSSIBLE\n";
  }
}

Test details

Test 1

Group: 1, 2

Verdict: ACCEPTED

input
3

correct output
1 2 3 

user output
1 2 3 
IMPOSSIBLE

Test 2

Group: 1, 2

Verdict:

input
4

correct output
IMPOSSIBLE

user output
3 1 2 3 
IMPOSSIBLE

Test 3

Group: 1, 2

Verdict: ACCEPTED

input
5

correct output
1 3 1 3 2 

user output
1 3 1 3 2 

Test 4

Group: 1, 2

Verdict: ACCEPTED

input
6

correct output
1 3 2 2 1 3 

user output
1 3 2 2 1 3 

Test 5

Group: 1, 2

Verdict:

input
7

correct output
IMPOSSIBLE

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

Test 8

Group: 1, 2

Verdict:

input
10

correct output
IMPOSSIBLE

user output
3 1 1 1 2 2 2 1 3 3 
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:

input
95

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

user output
(empty)

Test 11

Group: 2

Verdict:

input
96

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

user output
(empty)

Test 12

Group: 2

Verdict:

input
97

correct output
IMPOSSIBLE

user output
(empty)

Test 13

Group: 2

Verdict:

input
98

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

user output
(empty)

Test 14

Group: 2

Verdict:

input
99

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

user output
(empty)

Test 15

Group: 2

Verdict:

input
100

correct output
IMPOSSIBLE

user output
(empty)