Submission #251327

# Submission time Handle Problem Language Result Execution time Memory
251327 2020-07-20T19:50:11 Z Bruteforceman Lutrija (COCI19_lutrija) C++11
70 / 70
342 ms 376 KB
#include <bits/stdc++.h>
using namespace std;
map <long long, int> cmp;
bool isPrime(long long x) {
  if(x <= 1) return false;
  if(cmp.find(x) != cmp.end()) return cmp[x];
  for(int i = 2; 1LL * i * i <= x; i++) {
    if(x % i == 0) {
      return false;
    }
  }
  return cmp[x] = true;
}
void good(vector <long long> v) {
  for(auto i : v) if(!isPrime(i)) return ;
  for(int i = 1; i < v.size(); i++) if(!isPrime(abs(v[i] - v[i - 1]))) {
    return ;
  }
  cout << v.size() << endl;
  for(auto i : v) {
    cout << i << " ";
  }
  cout << endl;
  exit(0);
}
vector <long long> can;
vector <long long> now;
long long A, B;

void solve() {
  vector <long long> check = now;
  check.insert(check.begin(), A);
  check.insert(check.end(), B);
  good(check);
  for(auto i : can) {
    if(find(now.begin(), now.end(), i) == now.end()) {
      now.push_back(i);
      solve();
      now.pop_back( );
    }
  }
}
int main() {
  cin >> A >> B;
  can = vector <long long> ({2LL, A + 2, A - 2, B + 2, B - 2});
  solve();
  cout << -1 << endl;
  return 0;
}

Compilation message

lutrija.cpp: In function 'bool isPrime(long long int)':
lutrija.cpp:12:17: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   return cmp[x] = true;
lutrija.cpp: In function 'void good(std::vector<long long int>)':
lutrija.cpp:16:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 1; i < v.size(); i++) if(!isPrime(abs(v[i] - v[i - 1]))) {
                  ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 320 ms 356 KB Output is correct
2 Correct 234 ms 256 KB Output is correct
3 Correct 191 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 309 ms 256 KB Output is correct
2 Correct 201 ms 256 KB Output is correct
3 Correct 138 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 342 ms 376 KB Output is correct
2 Correct 250 ms 368 KB Output is correct
3 Correct 127 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 250 ms 256 KB Output is correct
2 Correct 171 ms 256 KB Output is correct
3 Correct 45 ms 256 KB Output is correct