結果

問題 No.282 おもりと天秤(2)
ユーザー izuru_matsuuraizuru_matsuura
提出日時 2016-06-14 18:45:21
言語 C++11
(gcc 11.4.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,886 bytes
コンパイル時間 1,572 ms
コンパイル使用メモリ 168,380 KB
実行使用メモリ 41,928 KB
平均クエリ数 30.79
最終ジャッジ日時 2023-09-24 00:07:13
合計ジャッジ時間 9,798 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
23,652 KB
testcase_01 AC 29 ms
24,252 KB
testcase_02 AC 23 ms
23,736 KB
testcase_03 AC 22 ms
23,628 KB
testcase_04 AC 22 ms
24,036 KB
testcase_05 AC 25 ms
24,060 KB
testcase_06 AC 29 ms
24,048 KB
testcase_07 AC 22 ms
23,388 KB
testcase_08 AC 29 ms
24,024 KB
testcase_09 AC 20 ms
24,240 KB
testcase_10 AC 874 ms
24,360 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

namespace {

    typedef double real;
    typedef long long ll;

    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        if (vs.empty()) return os << "[]";
        os << "[" << vs[0];
        for (int i = 1; i < vs.size(); i++) os << " " << vs[i];
        return os << "]";
    }
    template<class T> istream& operator>>(istream& is, vector<T>& vs) {
        for (auto it = vs.begin(); it != vs.end(); it++) is >> *it;
        return is;
    }

    int N;
    void input() {
        cin >> N;
    }

    void solve() {
        vector<vector<int>> F(N, vector<int>(N, -5));
        queue<pair<int, int>> Q;
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                Q.push(make_pair(i, j));
            }
        }
        while (not Q.empty()) {
            cout << "?";
            vector<bool> used(N, false);
            vector<pair<int, int>> V;
            set<pair<int,int>> S;
            for (int i = 0; V.size() < N && not Q.empty(); i++) {
                auto p = Q.front(); Q.pop();
                int a = p.first;
                int b = p.second;
                if (S.count(p)) {
                    Q.push(p);
                    break;
                }
                S.insert(p);
                if (used[a] || used[b]) {
                    Q.push(p);
                } else {
                    cout << " " << a+1 << " " << b+1;
                    used[a] = used[b] = true;
                    V.push_back(p);
                }
            }
            for (int i = V.size(); i < N; i++) {
                cout << " 0 0";
            }
            cout << endl;

            vector<char> C(N, '?');
            cin >> C;
            for (int i = 0; i < min(N, int(V.size())); i++) {
                int a = V[i].first;
                int b = V[i].second;
                if (C[i] == '>') {
                    F[a][b] = 1;
                    F[b][a] = -1;
                } else if (C[i] == '=') {
                    F[a][b] = 0;
                    F[b][a] = 0;
                } else {
                    assert(C[i] == '<');
                    F[a][b] = -1;
                    F[b][a] = 1;
                }
            }
            /*
            for (int i = 0; i < N; i++) {
                cout << F[i] << endl;
            }
            */
        }

        vector<pair<int,int>> xs;
        for (int i = 0; i < N; i++) {
            int c = 0;
            for (int j = 0; j < N; j++) {
                c += (F[i][j] == 1);
            }
            xs.push_back(make_pair(c, i));
        }
        sort(xs.begin(), xs.end());
        cout << "!";
        for (int i = 0; i < N; i++) {
            cout << " " << xs[i].second + 1;
        }
        cout << endl;
    }
}

int main() {
    input(); solve();
    return 0;
}

0