結果

問題 No.282 おもりと天秤(2)
ユーザー Mi_SawaMi_Sawa
提出日時 2015-09-19 20:25:15
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 339 ms / 5,000 ms
コード長 1,814 bytes
コンパイル時間 1,609 ms
コンパイル使用メモリ 157,288 KB
実行使用メモリ 24,468 KB
平均クエリ数 41.75
最終ジャッジ日時 2023-09-23 21:43:48
合計ジャッジ時間 6,397 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
23,400 KB
testcase_01 AC 26 ms
24,336 KB
testcase_02 AC 25 ms
24,312 KB
testcase_03 AC 25 ms
24,348 KB
testcase_04 AC 25 ms
24,012 KB
testcase_05 AC 24 ms
23,940 KB
testcase_06 AC 28 ms
23,676 KB
testcase_07 AC 24 ms
23,616 KB
testcase_08 AC 24 ms
23,568 KB
testcase_09 AC 22 ms
24,300 KB
testcase_10 AC 70 ms
23,484 KB
testcase_11 AC 164 ms
23,580 KB
testcase_12 AC 74 ms
23,412 KB
testcase_13 AC 85 ms
23,400 KB
testcase_14 AC 305 ms
23,568 KB
testcase_15 AC 311 ms
23,424 KB
testcase_16 AC 34 ms
23,616 KB
testcase_17 AC 97 ms
23,472 KB
testcase_18 AC 167 ms
23,340 KB
testcase_19 AC 205 ms
24,468 KB
testcase_20 AC 233 ms
23,568 KB
testcase_21 AC 339 ms
24,048 KB
testcase_22 AC 257 ms
23,820 KB
testcase_23 AC 22 ms
23,472 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i,b,n) for(int i=(int)(b);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
using namespace std;

vector<int> query(const int &n, vector<int> ord){//{{{
    if(rand() % 2) reverse(begin(ord), end(ord));
    if(rand() % 2){ ord.pop_back(); reverse(begin(ord), end(ord)); }
    if(ord.size() % 2) ord.pop_back();
    // rep(i, ord.size()/2) if(ord[i*2] < ord[i*2+1]) swap(ord[i*2], ord[i*2+1]);
    // return ord;
    cout << '?';
    rep(i, ord.size()) cout << ' ' << ord[i]+1;
    rep(_, 2 * n - ord.size()) cout << ' ' << 0;
    cout << endl; cout.flush();
    char ch;
    rep(i, ord.size()/2){
        cin >> ch;
        if(ch == '>') swap(ord[i*2], ord[i*2+1]);
    }
    rep(_, n - ord.size()/2) cin >> ch;
    return ord;
}//}}}

bool solve(){
    int n; cin >> n;
    vector<set<int>> g(n);
    rep(cnt, 2000){
        vector<int> deg(n), q;
        rep(u, n) for(auto &v : g[u]) ++deg[v];
        rep(u, n) if(!deg[u]) q.emplace_back(u);
        vector<int> ord;
        bool ok = true;
        while(!q.empty()){
            ok &= q.size() == 1;
            int idx = rand() % q.size();
            swap(q[idx], q.back());
            int u = q.back(); q.pop_back();
            ord.emplace_back(u);
            for(auto &v : g[u]) if(!--deg[v]) q.emplace_back(v);
        }
        if(ok){
            cerr << cnt << endl;
            cout << '!';
            rep(i, n) cout << ' ' << ord[i]+1;
            cout << endl;
            break;
        }
        auto res = query(n, ord);
        rep(i, res.size()/2) g[res[i*2]].emplace(res[i*2+1]);
    }
    return true;
}

signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}
// vim:set foldmethod=marker commentstring=//%s:
0