結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
23,976 KB
testcase_01 AC 24 ms
23,352 KB
testcase_02 AC 24 ms
23,484 KB
testcase_03 AC 24 ms
24,036 KB
testcase_04 AC 24 ms
23,328 KB
testcase_05 AC 24 ms
23,424 KB
testcase_06 AC 26 ms
23,604 KB
testcase_07 AC 24 ms
23,640 KB
testcase_08 AC 26 ms
23,688 KB
testcase_09 AC 24 ms
23,784 KB
testcase_10 AC 76 ms
24,348 KB
testcase_11 AC 169 ms
23,988 KB
testcase_12 AC 79 ms
24,228 KB
testcase_13 AC 85 ms
23,484 KB
testcase_14 AC 292 ms
24,036 KB
testcase_15 AC 310 ms
23,964 KB
testcase_16 AC 31 ms
23,856 KB
testcase_17 AC 96 ms
23,976 KB
testcase_18 AC 169 ms
23,844 KB
testcase_19 AC 211 ms
23,448 KB
testcase_20 AC 234 ms
23,988 KB
testcase_21 AC 333 ms
23,988 KB
testcase_22 AC 256 ms
23,604 KB
testcase_23 AC 24 ms
23,664 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;

// tr << ( vector, map, pair, tuple, etc... ) << endl//{{{
template <typename T, typename U>
struct sfinae_helper{typedef void type;};
template <typename T, typename U = void>
struct Print{ static ostream &pp(ostream &os, const T &x){ return os << x; } };
struct trace{//{{{
    ostream& os;
    trace(ostream& os): os(os) { }
    template<typename T>
        trace& operator<<(const T& x){ Print<T>::pp(os, x); return *this;}
    trace &operator<<(ostream& f(ostream&)){ f(os); return *this; }
    operator ostream &(){ return os; }
} tr(cout);//}}}
// string//{{{
template <> struct Print<string, void>{ static ostream &pp(ostream &os, const string &x){ return os << x; } };
//}}}
// Container//{{{
template <typename T> struct Print<T, typename sfinae_helper<T, typename T::iterator>::type>{
    static ostream &pp(ostream &os, const T &v){
        trace(os) << '[';
        for(const auto &x : v) trace(os) << x << ", ";
        return trace(os) << ']';
    }
};//}}}
// Pair//{{{
template <typename T> struct Print<T, typename sfinae_helper<T, typename T::first_type>::type>{
    static ostream &pp(ostream &os, const T &x){
        return trace(os) << '(' << x.first << ", " << x.second << ')';
    }
};//}}}
// Tuple//{{{
template<class T, size_t N> struct TuplePrint{
    static ostream &print(ostream &os, const T &x){
        TuplePrint<T, N-1>::print(os, x) << ", ";
        return trace(os) << get<N-1>(x);
        //return Print<decltype(get<N-1>(x))>::pp(os, get<N-1>(x));
    }
};
template<class T> struct TuplePrint<T, 1>{
    static ostream &print(ostream &os, const T &x){
        return trace(os) << get<0>(x);
    }
};
template <typename... Args>//Tuple
struct Print<tuple<Args...>>{
    static ostream &pp(ostream &os, const tuple<Args...> &x){
        os << "(";
        return TuplePrint<decltype(x), sizeof...(Args)>::print(os, x) << ")";
    }
};//}}}
//}}}
constexpr int N = 1000000;
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