結果

問題 No.1306 Exactly 2 Digits
ユーザー PachicobuePachicobue
提出日時 2020-12-03 20:46:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 299 ms / 2,000 ms
コード長 11,394 bytes
コンパイル時間 2,524 ms
コンパイル使用メモリ 219,344 KB
実行使用メモリ 25,436 KB
平均クエリ数 1236.78
最終ジャッジ日時 2024-07-17 09:02:42
合計ジャッジ時間 23,533 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
24,940 KB
testcase_01 AC 24 ms
25,196 KB
testcase_02 AC 23 ms
25,028 KB
testcase_03 AC 23 ms
24,836 KB
testcase_04 AC 22 ms
24,452 KB
testcase_05 AC 23 ms
24,964 KB
testcase_06 AC 23 ms
25,220 KB
testcase_07 AC 24 ms
24,580 KB
testcase_08 AC 24 ms
25,220 KB
testcase_09 AC 24 ms
25,220 KB
testcase_10 AC 24 ms
24,824 KB
testcase_11 AC 24 ms
25,220 KB
testcase_12 AC 24 ms
24,580 KB
testcase_13 AC 24 ms
24,940 KB
testcase_14 AC 24 ms
24,812 KB
testcase_15 AC 23 ms
25,196 KB
testcase_16 AC 24 ms
24,812 KB
testcase_17 AC 24 ms
25,184 KB
testcase_18 AC 24 ms
24,812 KB
testcase_19 AC 24 ms
24,812 KB
testcase_20 AC 24 ms
24,556 KB
testcase_21 AC 24 ms
25,040 KB
testcase_22 AC 23 ms
24,940 KB
testcase_23 AC 25 ms
25,196 KB
testcase_24 AC 24 ms
25,196 KB
testcase_25 AC 24 ms
24,812 KB
testcase_26 AC 24 ms
24,940 KB
testcase_27 AC 24 ms
24,940 KB
testcase_28 AC 24 ms
25,184 KB
testcase_29 AC 24 ms
24,940 KB
testcase_30 AC 24 ms
25,184 KB
testcase_31 AC 24 ms
24,556 KB
testcase_32 AC 25 ms
24,928 KB
testcase_33 AC 23 ms
24,556 KB
testcase_34 AC 25 ms
25,196 KB
testcase_35 AC 24 ms
25,196 KB
testcase_36 AC 24 ms
24,556 KB
testcase_37 AC 24 ms
24,812 KB
testcase_38 AC 26 ms
25,196 KB
testcase_39 AC 25 ms
25,052 KB
testcase_40 AC 25 ms
24,812 KB
testcase_41 AC 24 ms
24,556 KB
testcase_42 AC 25 ms
24,812 KB
testcase_43 AC 26 ms
25,196 KB
testcase_44 AC 27 ms
24,812 KB
testcase_45 AC 27 ms
24,812 KB
testcase_46 AC 30 ms
25,196 KB
testcase_47 AC 30 ms
24,812 KB
testcase_48 AC 33 ms
24,812 KB
testcase_49 AC 33 ms
24,940 KB
testcase_50 AC 35 ms
25,196 KB
testcase_51 AC 38 ms
25,324 KB
testcase_52 AC 41 ms
24,812 KB
testcase_53 AC 46 ms
24,812 KB
testcase_54 AC 44 ms
24,940 KB
testcase_55 AC 50 ms
25,436 KB
testcase_56 AC 53 ms
25,196 KB
testcase_57 AC 55 ms
25,196 KB
testcase_58 AC 58 ms
24,812 KB
testcase_59 AC 60 ms
24,556 KB
testcase_60 AC 72 ms
25,196 KB
testcase_61 AC 77 ms
24,812 KB
testcase_62 AC 77 ms
24,940 KB
testcase_63 AC 84 ms
24,556 KB
testcase_64 AC 83 ms
25,196 KB
testcase_65 AC 88 ms
24,812 KB
testcase_66 AC 101 ms
24,812 KB
testcase_67 AC 102 ms
24,940 KB
testcase_68 AC 102 ms
24,812 KB
testcase_69 AC 113 ms
24,940 KB
testcase_70 AC 114 ms
24,556 KB
testcase_71 AC 122 ms
25,196 KB
testcase_72 AC 126 ms
24,556 KB
testcase_73 AC 123 ms
25,196 KB
testcase_74 AC 147 ms
24,812 KB
testcase_75 AC 143 ms
24,812 KB
testcase_76 AC 164 ms
24,812 KB
testcase_77 AC 174 ms
24,556 KB
testcase_78 AC 187 ms
24,812 KB
testcase_79 AC 207 ms
24,916 KB
testcase_80 AC 214 ms
24,556 KB
testcase_81 AC 185 ms
24,812 KB
testcase_82 AC 229 ms
24,556 KB
testcase_83 AC 242 ms
25,196 KB
testcase_84 AC 260 ms
24,800 KB
testcase_85 AC 280 ms
24,556 KB
testcase_86 AC 228 ms
24,812 KB
testcase_87 AC 242 ms
25,196 KB
testcase_88 AC 299 ms
25,196 KB
testcase_89 AC 244 ms
25,196 KB
testcase_90 AC 223 ms
24,556 KB
testcase_91 AC 238 ms
24,812 KB
testcase_92 AC 226 ms
25,196 KB
testcase_93 AC 254 ms
24,940 KB
testcase_94 AC 219 ms
24,940 KB
testcase_95 AC 234 ms
24,812 KB
testcase_96 AC 208 ms
25,040 KB
testcase_97 AC 215 ms
25,124 KB
testcase_98 AC 198 ms
25,204 KB
testcase_99 AC 235 ms
24,556 KB
testcase_100 AC 235 ms
24,812 KB
testcase_101 AC 256 ms
24,940 KB
testcase_102 AC 216 ms
25,196 KB
testcase_103 AC 226 ms
25,196 KB
testcase_104 AC 230 ms
25,196 KB
testcase_105 AC 238 ms
25,324 KB
testcase_106 AC 210 ms
25,196 KB
testcase_107 AC 245 ms
24,812 KB
testcase_108 AC 226 ms
24,940 KB
testcase_109 AC 268 ms
25,196 KB
testcase_110 AC 212 ms
24,812 KB
testcase_111 AC 225 ms
25,196 KB
testcase_112 AC 202 ms
24,940 KB
testcase_113 AC 279 ms
24,556 KB
testcase_114 AC 281 ms
24,556 KB
testcase_115 AC 236 ms
24,556 KB
testcase_116 AC 291 ms
24,800 KB
testcase_117 AC 248 ms
24,812 KB
testcase_118 AC 266 ms
24,556 KB
testcase_119 AC 232 ms
24,940 KB
testcase_120 AC 207 ms
24,812 KB
testcase_121 AC 250 ms
25,196 KB
testcase_122 AC 244 ms
24,812 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