CSES - Datatähti 2021 loppu - Results
Submission details
Task:Kolmijako
Sender:Guuber
Submission time:2021-01-23 16:53:26 +0200
Language:C++ (C++17)
Status:COMPILE ERROR

Compiler report

input/code.cpp:4:1: error: 'strinb' does not name a type; did you mean 'stdin'?
 strinb b3(int a, int k){
 ^~~~~~
 stdin
input/code.cpp: In function 'int main()':
input/code.cpp:24:15: error: 'b3' was not declared in this scope
   string s2 = b3(i, n);
               ^~
input/code.cpp:27:13: error: conflicting declaration 'long long int s2'
   long long s2 = 0;
             ^~
input/code.cpp:24:10: note: previous declaration as 'std::__cxx11::string s2'
   string s2 = b3(i, n);
          ^~
input/code.cpp:28:20: error: no match for 'operator<' (operand types are 'int' and 'std::__cxx11::string {aka std::__cxx11::basic_string<char>}')
   for(int j = 0; j < s2; j++){
                  ~~^~~~
In file included from /usr/include/c++/7/regex:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:110,
                 from input/code.cpp:1:
/usr/include/c++/7/bits/regex.h:1004:5: note: candidate: template<class _BiIter> bool std::__cxx11::operator<(const std::__cxx11::s...

Code

#include<bits/stdc++.h>
using namespace std;

strinb b3(int a, int k){
	string s = "";
	while(a > 0){
		s += '0'+a%3;
		a /= 3;
	}
	while(s.size() < k) s += '0';
	reverse(s.begin(), s.end());
	return s;
}

int main(){
	int n;
	cin >> n;

	int kolme = 1;
	for(int i = 0; i < n; i++){
		kolme *= kolme;
	}
	for(int i = 0; i < kolme; i++){
		string s2 = b3(i, n);
		long long s0 = 0;
		long long s1 = 0;
		long long s2 = 0;
		for(int j = 0; j < s2; j++){
			if(s2[j] == '0') s0 += j+1;
			if(s2[j] == '1') s1 += j+1;
			if(s2[j] == '2') s2 += j+1;
		}
		if(s0 == s1-1 && s0 == s1-2) {
			for(auto u : s2){
				cout << u + 1 << " ";
			}
			cout << "\n";
			return 0;
		}
	}
	cout << "IMPOSSIBLE\n";
}