Submission #445263

# Submission time Handle Problem Language Result Execution time Memory
445263 2021-07-17T08:37:43 Z Dipto_Debdip Lutrija (COCI19_lutrija) C++14
0 / 70
175 ms 324 KB
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
ll isPrime(ll n) {
  if (n <= 1) return 0;
  if (n == 2) return 1;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) return 0;
  }
  return 1;
}
int main(int argc, char const *argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll a, b;
  cin >> a >> b;
  vector<ll> posA, posB, negA, negB, na, nb, pa, pb;
  for (ll i = a + 2; posA.size() < 28 && isPrime(i); i += 2) {
    posA.push_back(i);
  }
  posA.insert(posA.begin(), a);
  for (ll i = a - 2; negA.size() < 28 && isPrime(i); i - 2) {
    negA.push_back(i);
  }
  negA.insert(negA.begin(), a);
  for (ll i = b - 2; negB.size() < 28 && isPrime(i); i -= 2) {
    negB.push_back(i);
  }
  reverse(negB.begin(), negB.end());
  negB.push_back(b);
  for (ll i = b + 2; posB.size() < 28 && isPrime(i); i += 2) {
    posB.push_back(i);
  }
  reverse(posB.begin(), posB.end());
  posB.push_back(b);

  na = negA, nb = negB, pa = posA, pb = posB;
  for (ll i = (ll) nb.size() - 1; i >= 0; i--) {
    for (ll j = 0; j < pa.size(); j++) {
      if (isPrime(abs(pa[j] - nb[i]))) {
        cout << j + 1 + ((ll) nb.size() - i) << endl;
        for (ll jj = 0; jj <= j; jj++) cout << pa[jj] << " ";
        for (ll ii = i; ii < nb.size(); ii++) cout << nb[ii] << " ";
        cout << endl;
        return 0;
      }
    }
  }


  /*
pa pb
pa nb

na pb
na nb*/

  for (ll i = (ll) pb.size() - 1; i >= 0; i--) {
    for (ll j = 0; j < na.size(); j++) {
      if (isPrime(abs(na[j] - pb[i]))) {
        cout << j + 1 + ((ll) pb.size() - i) << endl;
        for (ll jj = 0; jj <= j; jj++) cout << na[jj] << " ";
        for (ll ii = i; ii < pb.size(); ii++) cout << pb[ii] << " ";
        cout << endl;
        return 0;
      }
    }
  }

  for (ll i = (ll) nb.size() - 1; i >= 0; i--) {
    for (ll j = 0; j < na.size(); j++) {
      if (isPrime(abs(na[j] - nb[i]))) {
        cout << j + 1 + ((ll) nb.size() - i) << endl;
        for (ll jj = 0; jj <= j; jj++) cout << na[jj] << " ";
        for (ll ii = i; ii < nb.size(); ii++) cout << nb[ii] << " ";
        cout << endl;
        return 0;
      }
    }
  }

  for (ll i = (ll) pb.size() - 1; i >= 0; i--) {
    for (ll j = 0; j < na.size(); j++) {
      if (isPrime(abs(na[j] - pb[i]))) {
        cout << j + 1 + ((ll) pb.size() - i) << endl;
        for (ll jj = 0; jj <= j; jj++) cout << na[jj] << " ";
        for (ll ii = i; ii < pb.size(); ii++) cout << pb[ii] << " ";
        cout << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;
  return 0;
}

Compilation message

lutrija.cpp: In function 'int main(int, const char**)':
lutrija.cpp:22:56: warning: for increment expression has no effect [-Wunused-value]
   22 |   for (ll i = a - 2; negA.size() < 28 && isPrime(i); i - 2) {
      |                                                      ~~^~~
lutrija.cpp:39:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |     for (ll j = 0; j < pa.size(); j++) {
      |                    ~~^~~~~~~~~~~
lutrija.cpp:43:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |         for (ll ii = i; ii < nb.size(); ii++) cout << nb[ii] << " ";
      |                         ~~~^~~~~~~~~~~
lutrija.cpp:59:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |     for (ll j = 0; j < na.size(); j++) {
      |                    ~~^~~~~~~~~~~
lutrija.cpp:63:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |         for (ll ii = i; ii < pb.size(); ii++) cout << pb[ii] << " ";
      |                         ~~~^~~~~~~~~~~
lutrija.cpp:71:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |     for (ll j = 0; j < na.size(); j++) {
      |                    ~~^~~~~~~~~~~
lutrija.cpp:75:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |         for (ll ii = i; ii < nb.size(); ii++) cout << nb[ii] << " ";
      |                         ~~~^~~~~~~~~~~
lutrija.cpp:83:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |     for (ll j = 0; j < na.size(); j++) {
      |                    ~~^~~~~~~~~~~
lutrija.cpp:87:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |         for (ll ii = i; ii < pb.size(); ii++) cout << pb[ii] << " ";
      |                         ~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 159 ms 288 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 157 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 175 ms 296 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 127 ms 324 KB Output isn't correct
2 Halted 0 ms 0 KB -