이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (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... |