Submission #404531

# Submission time Handle Problem Language Result Execution time Memory
404531 2021-05-14T14:25:39 Z penguinhacker Lutrija (COCI19_lutrija) C++14
0 / 70
2000 ms 332 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 (u^v&&!vis.count(v)&&prime(abs(u-v)))
			dfs(v);
}

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 316 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 332 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 2070 ms 204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2091 ms 204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2094 ms 204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2082 ms 204 KB Time limit exceeded
2 Halted 0 ms 0 KB -