結果
問題 | No.2496 LCM between Permutations |
ユーザー | risujiroh |
提出日時 | 2023-10-06 22:16:31 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 4,620 bytes |
コンパイル時間 | 3,165 ms |
コンパイル使用メモリ | 274,528 KB |
実行使用メモリ | 27,712 KB |
平均クエリ数 | 656.48 |
最終ジャッジ日時 | 2024-07-26 16:30:35 |
合計ジャッジ時間 | 6,770 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | RE | - |
testcase_01 | AC | 21 ms
24,836 KB |
testcase_02 | AC | 22 ms
24,964 KB |
testcase_03 | QLE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | QLE | - |
testcase_07 | QLE | - |
testcase_08 | AC | 24 ms
25,220 KB |
testcase_09 | RE | - |
testcase_10 | QLE | - |
testcase_11 | QLE | - |
testcase_12 | QLE | - |
testcase_13 | WA | - |
testcase_14 | RE | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | AC | 92 ms
27,712 KB |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
ソースコード
#if __INCLUDE_LEVEL__ == 0 #include __BASE_FILE__ namespace { void solve() { int n; cin >> n; auto query = [&](int i, int j) -> int { print('?', i, j); int x; cin >> x; return x; }; vector<pair<int, int>> pre(n * n + 1); for (int i : rep1(n)) { if (!atcoder::internal::is_prime_constexpr(i)) { continue; } for (int j : rep1(i + 1, n)) { if (i * j <= n) { continue; } if (!atcoder::internal::is_prime_constexpr(j)) { continue; } pre[i * j] = {i, j}; } } vector<int> ans(n + n, 1); if (3 <= n) { while (true) { int i = randint(1, n); int j = randint(1, n); int x = query(i, j); if (pre[x].first) { for (int k : rep(n + n)) { if (k < n) { ans[k] = query(k + 1, j); } else { ans[k] = query(i, k - n + 1); } } for (int z : rep(2)) { auto rng = ans | views::drop(n * z) | views::take(n); int mn = ranges::min(rng); for (int& e : rng) { e /= mn; } } break; } } } if (2 <= n) { vector<int> indices; for (int k : rep(n + n)) { if (ans[k] == 1) { indices.push_back(k); } } assert(len(indices) == 4); for (int za : rep(2)) { for (int zb : rep(2, 4)) { int x = query(indices[za] + 1, indices[zb] - n + 1); if (x == 1) { ans[indices[za ^ 1]] = query(indices[za ^ 1] + 1, indices[zb] - n + 1); ans[indices[zb ^ 1]] = query(indices[za] + 1, indices[zb ^ 1] - n + 1); } } } } print('!', ans); } } // namespace int main() { ios::sync_with_stdio(false); solve(); } #else // __INCLUDE_LEVEL__ #include <bits/stdc++.h> using namespace std; #include <atcoder/internal_math> template <class T, class U = T> bool chmin(T& x, U&& y) { return y < x && (x = forward<U>(y), true); } template <class T, class U = T> bool chmax(T& x, U&& y) { return x < y && (x = forward<U>(y), true); } namespace std { template <class T1, class T2> istream& operator>>(istream& is, pair<T1, T2>& p) { return is >> p.first >> p.second; } template <class... Ts> istream& operator>>(istream& is, tuple<Ts...>& t) { return apply([&is](auto&... xs) -> istream& { return (is >> ... >> xs); }, t); } template <class... Ts> istream& operator>>(istream& is, tuple<Ts&...>&& t) { return is >> t; } template <class R, enable_if_t<!is_convertible_v<R, string>>* = nullptr> auto operator>>(istream& is, R&& r) -> decltype(is >> *begin(r)) { for (auto&& e : r) { is >> e; } return is; } template <class T1, class T2> ostream& operator<<(ostream& os, const pair<T1, T2>& p) { return os << p.first << ' ' << p.second; } template <class... Ts> ostream& operator<<(ostream& os, const tuple<Ts...>& t) { auto f = [&os](const auto&... xs) -> ostream& { [[maybe_unused]] auto sep = ""; ((os << exchange(sep, " ") << xs), ...); return os; }; return apply(f, t); } template <class R, enable_if_t<!is_convertible_v<R, string_view>>* = nullptr> auto operator<<(ostream& os, R&& r) -> decltype(os << *begin(r)) { auto sep = ""; for (auto&& e : r) { os << exchange(sep, " ") << e; } return os; } } // namespace std template <class... Ts> void print(Ts&&... xs) { cout << tie(xs...) << '\n'; } inline mt19937_64 mt_engine( chrono::steady_clock::now().time_since_epoch().count()); template <bool Log = false> double uniform(double a, double b) { assert(a <= b); if constexpr (Log) { assert(0 < a); return exp(uniform(log(a), log(b))); } else { return uniform_real_distribution(a, b)(mt_engine); } } template <bool Log = false> int randint(int a, int b) { assert(a <= b); if constexpr (Log) { assert(0 < a); return round(uniform<true>(a - 0.5, b + 0.5)); } else { return uniform_int_distribution(a, b)(mt_engine); } } inline bool bernoulli(double p = 0.5) { assert(0 <= p && p <= 1); return bernoulli_distribution(p)(mt_engine); } inline auto rep(int l, int r) { return views::iota(min(l, r), r); } inline auto rep(int n) { return rep(0, n); } inline auto rep1(int l, int r) { return rep(l, r + 1); } inline auto rep1(int n) { return rep(1, n + 1); } inline auto per(int l, int r) { return rep(l, r) | views::reverse; } inline auto per(int n) { return per(0, n); } inline auto per1(int l, int r) { return per(l, r + 1); } inline auto per1(int n) { return per(1, n + 1); } inline auto len = ranges::ssize; #endif // __INCLUDE_LEVEL__