이 제출은 이전 버전의 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(intt u, intt end) {
visited[u] = true;
path.pb(u);
if (u == end) {
ok = true;
cout << path.size() << endl;
for(int i = 0; i < path.size(); i++) {
if(i < path.size() - 1 && v[path[i]] == v[path[i+1]]) {
continue;
}
if(v[path[i]] == v[end]) {
cout << v[path[i]] << " ";
return;
} else {
cout << v[path[i]] << " ";
}
}
return;
} else {
for (intt 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])) && 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(long long int, long long int)':
lutrija.cpp:34:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for(int i = 0; i < path.size(); i++) {
| ~~^~~~~~~~~~~~~
lutrija.cpp:35:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | if(i < path.size() - 1 && v[path[i]] == v[path[i+1]]) {
| ~~^~~~~~~~~~~~~~~~~
# | 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... |