This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define SPEED \
ios_base::sync_with_stdio(0); \
cin.tie(NULL); \
cout.tie(NULL);
#define pb push_back
// #define endl "\n"
#define ALL(x) x.begin(), x.end()
#define intt long long
const intt mxN = 2e5 + 5, L = 20, mxA = 5e5 + 35;
bool isprime(intt n) {
for(int i = 2; i <= sqrt(n); i++) {
if(n % i == 0) return false;
}
return true;
}
vector<vector<intt>>graph;
vector<intt> parent(mxN, 0), visited(mxN, 0), path, memopath, v(mxN);
bool ok = false;
void dfs(int u, int end) {
visited[u] = true;
path.pb(u);
if (u == end) {
ok = true;
for(int i = 0; i < path.size(); i++) {
if(v[path[i]] == v[end]) {
cout << v[path[i]] << " ";
return;
} else {
cout << v[path[i]] << " ";
}
}
return;
} else {
for (int v : graph[u]) {
if (!visited[v]) {
dfs(v, end);
}
}
}
path.pop_back();
visited[u] = false;
}
void solve() {
intt l,r, li =0, ri = 0;
cin >> l >> r;
v.resize(8);
v = {-mxA, 2, l - 2, r - 2, l, r, l + 2, r + 2};
sort(ALL(v));
graph.resize(8);
for(intt i = 1; i <= 7; i++) {
if(v[i] == l) li = i;
if(v[i] == r) ri = i;
for(intt j = i + 1; j <= 7; j++) {
if(isprime(v[i]) && isprime(v[j]) && isprime(abs(v[i]-v[j]))){
graph[i].pb(j);
graph[j].pb(i);
}
}
}
dfs(li, ri);
if(!ok) {
cout << -1 << endl;
}
}
int main() {
SPEED;
int tst = 1;
// cin >> tst;
while (tst--) {
solve();
}
return 0;
}
Compilation message (stderr)
lutrija.cpp: In function 'void dfs(int, int)':
lutrija.cpp:33:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | for(int i = 0; i < path.size(); i++) {
| ~~^~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |