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

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:8:6: error: expected type-specifier before 'Solver'
  new Solver(amo).Solve();
      ^~~~~~
input/code.cpp: At global scope:
input/code.cpp:14:6: error: expected unqualified-id before '[' token
  bool[] sieve = null;
      ^
input/code.cpp:15:5: error: expected unqualified-id before '[' token
  int[] ans = null;
     ^
input/code.cpp:17:9: error: expected ':' before 'Solver'
  public Solver(int amount) {
         ^~~~~~
input/code.cpp:22:9: error: expected ':' before 'void'
  public void Solve()
         ^~~~
input/code.cpp:65:28: error: expected ',' or '...' before 'args'
  static void Main(string[] args)
                            ^~~~
input/code.cpp:71:2: error: expected ';' after class definition
 }
  ^
  ;
input/code.cpp: In constructor 'Solver::Solver(int)':
input/code.cpp:19:3: error: 'sieve' was not declared in this scope
   sieve = new bool[amo];
   ^~~~~
input/code.cpp:20:3: error: 'ans' was not declared in this...

Code

#include <iostream>

using namespace std;

int main() {
    int amo;
    cin >> amo;
	new Solver(amo).Solve();
}

class Solver
{

	bool[] sieve = null;
	int[] ans = null;
	int amo = 0;
	public Solver(int amount) {
		amo = amount;
		sieve = new bool[amo];
		ans = new int[amo];
	}
	public void Solve()
	{
		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;
		}
	}
	bool 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 swap(int a, int b)
	{
		if (a == b) return;
		int t = ans[a];
		ans[a] = ans[b];
		ans[b] = t;
	}

	static void Main(string[] args)
	{
		new Solver(50).Solve();


	}
}