結果

問題 No.1306 Exactly 2 Digits
ユーザー PachicobuePachicobue
提出日時 2020-12-03 20:46:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 294 ms / 2,000 ms
コード長 11,394 bytes
コンパイル時間 2,337 ms
コンパイル使用メモリ 215,460 KB
実行使用メモリ 24,408 KB
平均クエリ数 1236.78
最終ジャッジ日時 2023-09-24 08:37:36
合計ジャッジ時間 23,228 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
24,240 KB
testcase_01 AC 25 ms
24,012 KB
testcase_02 AC 25 ms
23,820 KB
testcase_03 AC 25 ms
23,376 KB
testcase_04 AC 26 ms
24,252 KB
testcase_05 AC 25 ms
23,364 KB
testcase_06 AC 26 ms
24,024 KB
testcase_07 AC 25 ms
23,832 KB
testcase_08 AC 25 ms
23,832 KB
testcase_09 AC 25 ms
24,000 KB
testcase_10 AC 26 ms
23,508 KB
testcase_11 AC 25 ms
23,388 KB
testcase_12 AC 27 ms
24,048 KB
testcase_13 AC 26 ms
23,424 KB
testcase_14 AC 27 ms
23,376 KB
testcase_15 AC 26 ms
24,012 KB
testcase_16 AC 27 ms
24,372 KB
testcase_17 AC 26 ms
23,412 KB
testcase_18 AC 26 ms
24,024 KB
testcase_19 AC 26 ms
23,376 KB
testcase_20 AC 25 ms
23,376 KB
testcase_21 AC 26 ms
23,376 KB
testcase_22 AC 25 ms
23,400 KB
testcase_23 AC 27 ms
24,324 KB
testcase_24 AC 27 ms
24,012 KB
testcase_25 AC 27 ms
23,640 KB
testcase_26 AC 26 ms
23,508 KB
testcase_27 AC 27 ms
23,400 KB
testcase_28 AC 26 ms
23,376 KB
testcase_29 AC 27 ms
23,628 KB
testcase_30 AC 27 ms
23,652 KB
testcase_31 AC 27 ms
23,520 KB
testcase_32 AC 27 ms
23,388 KB
testcase_33 AC 27 ms
24,396 KB
testcase_34 AC 28 ms
24,024 KB
testcase_35 AC 28 ms
24,024 KB
testcase_36 AC 28 ms
23,628 KB
testcase_37 AC 28 ms
24,048 KB
testcase_38 AC 27 ms
23,640 KB
testcase_39 AC 28 ms
23,628 KB
testcase_40 AC 28 ms
24,324 KB
testcase_41 AC 27 ms
24,324 KB
testcase_42 AC 28 ms
23,400 KB
testcase_43 AC 29 ms
23,400 KB
testcase_44 AC 30 ms
24,036 KB
testcase_45 AC 31 ms
24,036 KB
testcase_46 AC 32 ms
23,412 KB
testcase_47 AC 33 ms
23,844 KB
testcase_48 AC 36 ms
23,388 KB
testcase_49 AC 36 ms
23,664 KB
testcase_50 AC 39 ms
23,652 KB
testcase_51 AC 41 ms
24,036 KB
testcase_52 AC 45 ms
23,652 KB
testcase_53 AC 47 ms
23,640 KB
testcase_54 AC 46 ms
24,024 KB
testcase_55 AC 51 ms
23,664 KB
testcase_56 AC 55 ms
23,820 KB
testcase_57 AC 57 ms
23,820 KB
testcase_58 AC 61 ms
24,036 KB
testcase_59 AC 60 ms
23,424 KB
testcase_60 AC 73 ms
23,700 KB
testcase_61 AC 79 ms
23,628 KB
testcase_62 AC 80 ms
24,036 KB
testcase_63 AC 86 ms
23,616 KB
testcase_64 AC 84 ms
23,652 KB
testcase_65 AC 90 ms
23,640 KB
testcase_66 AC 99 ms
24,408 KB
testcase_67 AC 103 ms
24,252 KB
testcase_68 AC 103 ms
23,412 KB
testcase_69 AC 113 ms
23,652 KB
testcase_70 AC 118 ms
24,024 KB
testcase_71 AC 124 ms
24,036 KB
testcase_72 AC 123 ms
23,520 KB
testcase_73 AC 124 ms
23,652 KB
testcase_74 AC 146 ms
23,364 KB
testcase_75 AC 144 ms
23,640 KB
testcase_76 AC 162 ms
24,048 KB
testcase_77 AC 176 ms
23,412 KB
testcase_78 AC 190 ms
24,036 KB
testcase_79 AC 204 ms
23,520 KB
testcase_80 AC 214 ms
23,388 KB
testcase_81 AC 183 ms
23,832 KB
testcase_82 AC 230 ms
24,012 KB
testcase_83 AC 242 ms
23,640 KB
testcase_84 AC 260 ms
24,264 KB
testcase_85 AC 281 ms
23,508 KB
testcase_86 AC 230 ms
24,120 KB
testcase_87 AC 244 ms
24,372 KB
testcase_88 AC 294 ms
23,640 KB
testcase_89 AC 243 ms
23,352 KB
testcase_90 AC 227 ms
23,820 KB
testcase_91 AC 236 ms
24,408 KB
testcase_92 AC 224 ms
23,376 KB
testcase_93 AC 254 ms
23,364 KB
testcase_94 AC 214 ms
24,036 KB
testcase_95 AC 232 ms
23,628 KB
testcase_96 AC 210 ms
23,400 KB
testcase_97 AC 223 ms
23,628 KB
testcase_98 AC 206 ms
24,036 KB
testcase_99 AC 234 ms
24,024 KB
testcase_100 AC 234 ms
23,376 KB
testcase_101 AC 260 ms
23,352 KB
testcase_102 AC 210 ms
23,820 KB
testcase_103 AC 227 ms
23,508 KB
testcase_104 AC 228 ms
23,364 KB
testcase_105 AC 240 ms
23,376 KB
testcase_106 AC 210 ms
24,024 KB
testcase_107 AC 240 ms
24,360 KB
testcase_108 AC 225 ms
23,676 KB
testcase_109 AC 268 ms
24,060 KB
testcase_110 AC 214 ms
23,388 KB
testcase_111 AC 230 ms
23,388 KB
testcase_112 AC 204 ms
24,036 KB
testcase_113 AC 274 ms
23,520 KB
testcase_114 AC 274 ms
24,348 KB
testcase_115 AC 238 ms
24,024 KB
testcase_116 AC 285 ms
23,364 KB
testcase_117 AC 244 ms
24,348 KB
testcase_118 AC 262 ms
23,844 KB
testcase_119 AC 233 ms
24,012 KB
testcase_120 AC 208 ms
23,520 KB
testcase_121 AC 241 ms
24,372 KB
testcase_122 AC 241 ms
24,036 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using ll = long long;
using uint = unsigned int;
using ull = unsigned long long;
using ld = long double;
template<typename T> using max_heap = std::priority_queue<T>;
template<typename T> using min_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
constexpr int popcount(const ull v) { return v ? __builtin_popcountll(v) : 0; }
constexpr int log2p1(const ull v) { return v ? 64 - __builtin_clzll(v) : 0; }
constexpr int lsbp1(const ull v) { return __builtin_ffsll(v); }
constexpr int clog(const ull v) { return v ? log2p1(v - 1) : 0; }
constexpr ull ceil2(const ull v) { return 1ULL << clog(v); }
constexpr ull floor2(const ull v) { return v ? (1ULL << (log2p1(v) - 1)) : 0ULL; }
constexpr bool btest(const ull mask, const int ind) { return (mask >> ind) & 1ULL; }
template<typename T> void bset(T& mask, const int ind) { mask |= ((T)1 << ind); }
template<typename T> void breset(T& mask, const int ind) { mask &= ~((T)1 << ind); }
template<typename T> void bflip(T& mask, const int ind) { mask ^= ((T)1 << ind); }
template<typename T> void bset(T& mask, const int ind, const bool b) { (b ? bset(mask, ind) : breset(mask, ind)); }
template<typename T> bool chmin(T& a, const T& b) { return (a > b ? a = b, true : false); }
template<typename T> bool chmax(T& a, const T& b) { return (a < b ? a = b, true : false); }
template<typename T> constexpr T inf_v = std::numeric_limits<T>::max() / 4;
template<typename Real> constexpr Real pi_v = Real{3.141592653589793238462643383279502884};
template<typename T> constexpr T TEN(const int n) { return n == 0 ? T{1} : TEN<T>(n - 1) * T{10}; }
template<typename F> struct fix : F
{
    fix(F&& f) : F{std::forward<F>(f)} {}
    template<typename... Args> auto operator()(Args&&... args) const { return F::operator()(*this, std::forward<Args>(args)...); }
};
template<typename T, int n, int i = 0>
auto nd_array(int const (&szs)[n], const T x = T{})
{
    if constexpr (i == n) {
        return x;
    } else {
        return std::vector(szs[i], nd_array<T, n, i + 1>(szs, x));
    }
}
template<typename T, std::size_t N>
std::ostream& operator<<(std::ostream& os, const std::array<T, N>& v)
{
    os << "[";
    for (const auto& e : v) { os << e << ","; }
    return (os << "]" << std::endl);
}
template<typename T, typename A>
std::ostream& operator<<(std::ostream& os, const std::deque<T, A>& v)
{
    os << "[";
    for (const auto& e : v) { os << e << ","; }
    return (os << "]" << std::endl);
}
template<typename K, typename T, typename C, typename A>
std::ostream& operator<<(std::ostream& os, const std::map<K, T, C, A>& v)
{
    os << "[";
    for (const auto& e : v) { os << "<" << e.first << ": " << e.second << ">,"; }
    return (os << "]" << std::endl);
}
template<typename K, typename T, typename C, typename A>
std::ostream& operator<<(std::ostream& os, const std::multimap<K, T, C, A>& v)
{
    os << "[";
    for (const auto& e : v) { os << "<" << e.first << ": " << e.second << ">,"; }
    return (os << "]" << std::endl);
}
template<typename T, typename C, typename A>
std::ostream& operator<<(std::ostream& os, const std::multiset<T, C, A>& v)
{
    os << "[";
    for (const auto& e : v) { os << e << ","; }
    return (os << "]" << std::endl);
}
template<typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& v) { return (os << "<" << v.first << "," << v.second << ">"); }
template<typename T1, typename T2, typename T3>
std::ostream& operator<<(std::ostream& os, const std::priority_queue<T1, T2, T3>& v)
{
    auto q = v;
    os << "[";
    while (not q.empty()) { os << q.top() << ",", q.pop(); }
    return os << "]\n";
}
template<typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, const std::queue<T1>& v)
{
    auto q = v;
    os << "[";
    while (not q.empty()) { os << q.front() << ",", q.pop(); }
    return os << "]\n";
}
template<typename T, typename C, typename A>
std::ostream& operator<<(std::ostream& os, const std::set<T, C, A>& v)
{
    os << "[";
    for (const auto& e : v) { os << e << ","; }
    return (os << "]" << std::endl);
}
template<typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, const std::stack<T1>& v)
{
    auto q = v;
    os << "[";
    while (not q.empty()) { os << q.top() << ",", q.pop(); }
    return os << "]\n";
}
template<typename TupType, size_t... I>
std::ostream& print(std::ostream& os, const TupType& _tup, std::index_sequence<I...>) { return os << "(", (..., (os << (I == 0 ? "" : ", ") << std::get<I>(_tup))), os << ")\n"; }
template<typename... T>
std::ostream& operator<<(std::ostream& os, const std::tuple<T...>& _tup) { return print(os, _tup, std::make_index_sequence<sizeof...(T)>()); }
template<typename K, typename T, typename H, typename P, typename A>
std::ostream& operator<<(std::ostream& os, const std::unordered_map<K, T, H, P, A>& v)
{
    os << "[";
    for (const auto& e : v) { os << "<" << e.first << ": " << e.second << ">,"; }
    return (os << "]" << std::endl);
}
template<typename K, typename T, typename H, typename P, typename A>
std::ostream& operator<<(std::ostream& os, const std::unordered_multimap<K, T, H, P, A>& v)
{
    os << "[";
    for (const auto& e : v) { os << "<" << e.first << ": " << e.second << ">,"; }
    return (os << "]" << std::endl);
}
template<typename T, typename H, typename P, typename A>
std::ostream& operator<<(std::ostream& os, const std::unordered_multiset<T, H, P, A>& v)
{
    os << "[";
    for (const auto& e : v) { os << e << ","; }
    return (os << "]" << std::endl);
}
template<typename T, typename H, typename P, typename A>
std::ostream& operator<<(std::ostream& os, const std::unordered_set<T, H, P, A>& v)
{
    os << "[";
    for (const auto& e : v) { os << e << ","; }
    return (os << "]" << std::endl);
}
template<typename T, typename A>
std::ostream& operator<<(std::ostream& os, const std::vector<T, A>& v)
{
    os << "[";
    for (const auto& e : v) { os << e << ","; }
    return (os << "]" << std::endl);
}
class printer
{
public:
    printer(std::ostream& os_ = std::cout) : m_os{os_} { m_os << std::fixed << std::setprecision(15); }
    template<typename... Args> int ln(const Args&... args) { return dump(args...), m_os << '\n', 0; }
    template<typename... Args> int el(const Args&... args) { return dump(args...), m_os << std::endl, 0; }
private:
    template<typename T> void dump(const T& v) { m_os << v; }
    template<typename T> void dump(const std::vector<T>& vs)
    {
        for (int i = 0; i < (int)vs.size(); i++) { m_os << (i ? " " : ""), dump(vs[i]); }
    }
    template<typename T> void dump(const std::vector<std::vector<T>>& vss)
    {
        for (int i = 0; i < (int)vss.size(); i++) { m_os << (0 <= i or i + 1 < (int)vss.size() ? "\n" : ""), dump(vss[i]); }
    }
    template<typename T, typename... Args> int dump(const T& v, const Args&... args) { return dump(v), m_os << ' ', dump(args...), 0; }
    std::ostream& m_os;
};
printer out;
class scanner
{
public:
    scanner(std::istream& is_ = std::cin) : m_is{is_} { m_is.tie(nullptr), std::ios::sync_with_stdio(false); }
    void reset_opt() { m_is.tie(), std::ios::sync_with_stdio(); }
    template<typename T> T val()
    {
        T v;
        return m_is >> v, v;
    }
    template<typename T> T val(const T offset) { return val<T>() - offset; }
    template<typename T> std::vector<T> vec(const int n)
    {
        return make_v<T>(n, [this]() { return val<T>(); });
    }
    template<typename T> std::vector<T> vec(const int n, const T offset)
    {
        return make_v<T>(n, [this, offset]() { return val<T>(offset); });
    }
    template<typename T> std::vector<std::vector<T>> vvec(const int n0, const int n1)
    {
        return make_v<std::vector<T>>(n0, [this, n1]() { return vec<T>(n1); });
    }
    template<typename T> std::vector<std::vector<T>> vvec(const int n0, const int n1, const T offset)
    {
        return make_v<std::vector<T>>(n0, [this, n1, offset]() { return vec<T>(n1, offset); });
    }
    template<typename... Args> auto tup() { return std::tuple<std::decay_t<Args>...>{val<Args>()...}; }
    template<typename... Args> auto tup(const Args&... offsets) { return std::tuple<std::decay_t<Args>...>{val<Args>(offsets)...}; }
private:
    template<typename T, typename F>
    std::vector<T> make_v(const int n, F f)
    {
        std::vector<T> ans;
        for (int i = 0; i < n; i++) { ans.push_back(f()); }
        return ans;
    }
    std::istream& m_is;
};
scanner in;
template<typename T>
void HogeHogeSansuu(T x) { std::cerr << x; }
template<typename T, typename... Args>
void HogeHogeSansuu(T x, Args... args) { std::cerr << x << ",", HogeHogeSansuu(args...); }
int main()
{
    in.reset_opt();
    const int N = in.val<int>();
    const int L = N * N - N;
    using pii = std::pair<int, int>;
    auto ask = [&](const int i, const int j) {
        out.el('?', i + 1, j + 1);
        const auto [p, q] = in.tup<int, int>();
        return std::make_pair(p, q);
    };
    auto fin = [&](const std::vector<int>& ans) { out.el('!', ans); };
    auto diff = [&](const int m, const int n) {
        const auto [p, q] = std::minmax({m / N - n / N, m % N - n % N});
        return std::make_pair(p, q);
    };
    std::vector<pii> ds(L, {0, 0});
    for (int i = 1; i < L; i++) { ds[i] = ask(i, 0); }
    std::vector<int> as(L, -1);
    const int mi = std::min_element(ds.begin(), ds.end()) - ds.begin();
    const int Mi = std::max_element(ds.begin(), ds.end()) - ds.begin();
    as[mi] = N, as[Mi] = N * N - 1;
    auto getcand = [&](const int n, const pii d) {
        std::vector<int> ans;
        for (int c = N; c < N * N; c++) {
            if (diff(n, c) == d) { ans.push_back(c); }
        }
        return ans;
    };
    auto decide = [&](const int m, const pii& md, const int n, const pii& nd) {
        std::vector<int> ans;
        const auto cs = getcand(m, md);
        for (const int c : cs) {
            assert(diff(m, c) == md);
            if (diff(n, c) == nd) { ans.push_back(c); }
        }
        assert(ans.size() == 1);
        return ans[0];
    };
    as[0] = decide(N, ds[mi], N * N - 1, ds[Mi]);
    (std::cerr << "LINE " << 54 << ": " << "(" << "as[0], mi, Mi" << ") = ("), HogeHogeSansuu(as[0], mi, Mi), std::cerr << ")" << std::endl;
    int ref = mi;
    {
        const int p = as[0] / N, q = as[0] % N;
        if ((p + q) % 2 == 1) { ref = Mi; }
    }
    std::vector<bool> used(N * N, false);
    used[N] = used[as[0]] = used[N * N - 1] = true;
    for (int i = 1; i < L; i++) {
        const auto cs = getcand(as[0], pii{-ds[i].second, -ds[i].first});
        (std::cerr << "LINE " << 65 << ": " << "(" << "i, cs" << ") = ("), HogeHogeSansuu(i, cs), std::cerr << ")" << std::endl;
        if (cs.size() == 1) {
            as[i] = cs[0];
        } else if (cs.size() == 2) {
            if (used[cs[0]]) {
                as[i] = cs[1];
            } else if (used[cs[1]]) {
                as[i] = cs[0];
            } else {
                const auto d = ask(ref, i);
                as[i] = decide(as[0], pii{-ds[i].second, -ds[i].first}, as[ref], d);
            }
        } else {
            assert(false);
        }
        (std::cerr << "LINE " << 80 << ": " << "(" << "i, as[i]" << ") = ("), HogeHogeSansuu(i, as[i]), std::cerr << ")" << std::endl;
        used[as[i]] = true;
    }
    fin(as);
    return 0;
}
0