Submission #404553

# Submission time Handle Problem Language Result Execution time Memory
404553 2021-05-14T15:29:55 Z penguinhacker Lutrija (COCI19_lutrija) C++14
0 / 70
2000 ms 204 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ar array

ll a, b;
vector<ll> c, p;
set<int> vis;

bool prime(ll n) {
	for (int i=2; i*i<=n; ++i)
		if (n%i==0)
			return 0;
	return n>=2;
}

void add(ll n) {
	c.push_back(n);
	if (prime(n-2))
		c.push_back(n-2);
	if (prime(n+2))
		c.push_back(n+2);
}

void dfs(ll u) {
	p.push_back(u), vis.insert(u);
	if (u==b) {
		cout << p.size() << "\n";
		for (ll i : p)
			cout << i << " ";
		exit(0);
	}
	for (ll v : c)
		if (!vis.count(v)&&prime(abs(u-v)))
			dfs(v);
	p.pop_back();
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> a >> b;
	add(a), add(b);
	sort(c.begin(), c.end());
	c.resize(unique(c.begin(), c.end())-c.begin());
	dfs(a);
	cout << -1;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2084 ms 204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2079 ms 204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2085 ms 204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2079 ms 204 KB Time limit exceeded
2 Halted 0 ms 0 KB -