# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
308489 | 2020-10-01T12:35:42 Z | ErdosSzekeres | Lutrija (COCI19_lutrija) | C++14 | 172 ms | 18584 KB |
#include<bits/stdc++.h> using namespace std; #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define ll long long const int MAXN = 1e7 + 7; vector<int> G[20]; int dist[20], pred[20]; vector<ll> primos; bool composto[MAXN]; bool primality_test(ll x){ if(x < MAXN)return !composto[x]; //x eh bem grande for(int i=0; i<(int)primos.size(); i++){ if(x%primos[i] == 0)return false; } return true; } int main(){ fastio; composto[1] = true; for(int i=2; i<MAXN; i++){ if(composto[i])continue; primos.push_back(i); for(int j=2*i; j<MAXN; j+=i)composto[j]=true; } ll a,b; cin>>a>>b; set<ll> candidates; candidates.insert(2); candidates.insert(a-2);candidates.insert(a);candidates.insert(a+2); candidates.insert(b-2);candidates.insert(b);candidates.insert(b+2); vector<ll> nodes; int cnt = 0; int source, dest; for(auto it : candidates){ if(it < 2)continue; if(it == a){nodes.push_back(it); source = cnt++; continue;} if(it == b){nodes.push_back(it); dest = cnt++; continue;} if(!primality_test(it))continue; nodes.push_back(it); cnt++; } for(int i=0; i<(int)nodes.size(); i++){ dist[i] = MAXN; for(int j=i+1; j<(int)nodes.size(); j++){ ll val = nodes[j] - nodes[i]; if(val < 0)val = -val; if(primality_test(val)){ G[i].push_back(j); G[j].push_back(i); } } } dist[source] = 0; pred[source] = -1; queue<int> bfs; bfs.push(source); while(!bfs.empty()){ int u = bfs.front(); bfs.pop(); for(int viz : G[u]){ if(dist[viz] > dist[u] + 1){ dist[viz] = dist[u] + 1; pred[viz] = u; bfs.push(viz); } } } if(dist[dest] == MAXN){ cout<<"-1"<<endl; }else{ cout << dist[dest] + 1 << endl; vector<ll> aux; while(dest != -1){ aux.push_back(nodes[dest]); dest = pred[dest]; } reverse(aux.begin(), aux.end()); for(int it : aux){ cout<<it<<" "; } cout<<endl; } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 140 ms | 18408 KB | Output is correct |
2 | Correct | 141 ms | 18468 KB | Output is correct |
3 | Correct | 151 ms | 18532 KB | Output is correct |
4 | Correct | 139 ms | 18544 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 147 ms | 18496 KB | Output is correct |
2 | Correct | 144 ms | 18584 KB | Output is correct |
3 | Correct | 145 ms | 18532 KB | Output is correct |
4 | Correct | 144 ms | 18404 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 142 ms | 18408 KB | Output is correct |
2 | Correct | 147 ms | 18408 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 149 ms | 18404 KB | Output is correct |
2 | Correct | 143 ms | 18404 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 150 ms | 18408 KB | Output is correct |
2 | Correct | 146 ms | 18528 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 146 ms | 18536 KB | Output is correct |
2 | Correct | 146 ms | 18480 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 166 ms | 18408 KB | Integer parameter [name=arr[4]] equals to -2039078211, violates the range [1, 1000000000000000] |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 171 ms | 18536 KB | Integer parameter [name=arr[1]] equals to -2145466189, violates the range [1, 1000000000000000] |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 169 ms | 18464 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 172 ms | 18408 KB | Integer parameter [name=arr[4]] equals to -2070243847, violates the range [1, 1000000000000000] |
2 | Halted | 0 ms | 0 KB | - |