CSES - Putka Open 2020 – 1/5 - Results
Submission details
Task:Lista
Sender:Grez
Submission time:2020-09-06 12:49:27 +0300
Language:C++ (C++17)
Status:COMPILE ERROR

Compiler report

input/code.cpp:10:9: error: ISO C++ forbids declaration of 'Solve' with no type [-fpermissive]
   Solve();
         ^
input/code.cpp:5:1: error: new types may not be defined in a return type
 class Solver
 ^~~~~
input/code.cpp:5:1: note: (perhaps a semicolon is missing after the definition of 'Solver')
input/code.cpp:16:26: error: return type specification for constructor invalid
 Solver::Solver(int amount) {
                          ^
input/code.cpp:25:31: error: no 'void Solver::swap(int, int)' member function declared in class 'Solver'
 void Solver::swap(int a, int b)
                               ^
input/code.cpp:32:29: error: no 'bool Solver::recurse(int)' member function declared in class 'Solver'
 bool Solver::recurse(int pos)
                             ^
input/code.cpp:45:6: error: prototype for 'void Solver::Solve()' does not match any in class 'Solver'
 void Solver::Solve(void)
      ^~~~~~
input/code.cpp:10:3: error: candidate is: int Solver::Solve()
   Solve();...

Code

#include <iostream>
using namespace std;
class Solver
{
public:
Solver(int amount);
~Solver();
Solve();
private:
bool* sieve;
int* ans;
int amo;
}
Solver::Solver(int amount) {
amo = amount;
sieve = new bool(amo);
ans = new int(amo);
}
Solver::~Solver() {
delete sieve;
delete ans;
}
void Solver::swap(int a, int b)
{
if (a == b) return;
int t = ans[a];
ans[a] = ans[b];
ans[b] = t;
}
bool Solver::recurse(int pos)
{
for (int other = pos; other >= 0; other -= 2)
{
if (sieve[(ans[other] + ans[pos + 1]) / 2]) continue;
if (pos == 0) return true;
swap(pos, other);
if (recurse(pos - 1)) return true;
swap(pos, other); //swap back
}
return false;
}
void Solver::Solve(void)
{
int maxPrime = amo * 2;
for (int mul = 3; (mul * mul) < maxPrime; mul += 2)
{
for (int hole = mul / 2 + mul; hole < amo; hole += mul)
{
sieve[hole] = true;
}
}
for (int i = 0; i < amo; i++) { ans[i] = i + 1; }
if (recurse(amo - 2))
{
for (int i=0; i<amo; i++) {
cout << ans[i];
}
count << endl;
}
}
int main() {
int amo;
cin >> amo;
new Solver(amo).Solve();
}