結果

問題 No.1955 Not Prime
ユーザー KudeKude
提出日時 2022-05-21 01:04:13
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 1,653 bytes
コンパイル時間 2,865 ms
コンパイル使用メモリ 236,820 KB
実行使用メモリ 16,936 KB
最終ジャッジ日時 2023-10-20 15:23:02
合計ジャッジ時間 5,787 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
5,556 KB
testcase_01 AC 66 ms
5,556 KB
testcase_02 AC 66 ms
5,556 KB
testcase_03 AC 66 ms
5,556 KB
testcase_04 AC 68 ms
5,556 KB
testcase_05 AC 68 ms
5,556 KB
testcase_06 AC 69 ms
5,700 KB
testcase_07 AC 75 ms
6,464 KB
testcase_08 AC 74 ms
6,208 KB
testcase_09 AC 69 ms
6,208 KB
testcase_10 AC 66 ms
5,584 KB
testcase_11 AC 86 ms
16,936 KB
testcase_12 AC 69 ms
5,708 KB
testcase_13 AC 73 ms
6,464 KB
testcase_14 AC 71 ms
5,812 KB
testcase_15 AC 70 ms
5,712 KB
testcase_16 AC 70 ms
6,208 KB
testcase_17 AC 78 ms
7,504 KB
testcase_18 AC 74 ms
6,464 KB
testcase_19 AC 76 ms
7,256 KB
testcase_20 AC 69 ms
5,556 KB
testcase_21 AC 70 ms
5,732 KB
testcase_22 AC 70 ms
5,556 KB
testcase_23 AC 68 ms
5,556 KB
testcase_24 AC 67 ms
5,556 KB
testcase_25 AC 68 ms
5,556 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic pop
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

bool is_prime[1000000];
bool ok[1000][1000];

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  for(int p = 2; p < 1000000; p++) is_prime[p] = true;
  for(int p = 2; p < 1000000; p++) if (is_prime[p]) {
    for(int q = 2 * p; q < 1000000; q += p) is_prime[q] = false;
  }
  for(int x = 1; x < 1000; x++) {
    for(int y = 1; y < 1000; y++) {
      ok[x][y] = !is_prime[stoi(to_string(x) + to_string(y))];
    }
  }
  int n;
  cin >> n;
  VI a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];
  two_sat ts(n);
  rep(i, n) rep(bi, 2) {
    if (!ok[a[i]][b[i]]) {
      ts.add_clause(i, !bi, i, !bi);
    }
    swap(a[i], b[i]);
  }
  rep(i, n) rep(j, i) {
    rep(bi, 2) {
      rep(bj, 2) {
        if (!ok[a[i]][b[j]] || !ok[a[j]][b[i]]) {
          ts.add_clause(i, !bi, j, !bj);
        }
        swap(a[j], b[j]);
      }
      swap(a[i], b[i]);
    }
  }
  cout << (ts.satisfiable() ? "Yes\n" : "No\n");
}
0