結果

問題 No.282 おもりと天秤(2)
ユーザー face4face4
提出日時 2019-11-20 15:28:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,784 ms / 5,000 ms
コード長 1,542 bytes
コンパイル時間 751 ms
コンパイル使用メモリ 76,744 KB
実行使用メモリ 24,312 KB
平均クエリ数 267.12
最終ジャッジ日時 2023-09-24 02:21:19
合計ジャッジ時間 19,849 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
23,352 KB
testcase_01 AC 29 ms
24,312 KB
testcase_02 AC 26 ms
23,364 KB
testcase_03 AC 26 ms
23,364 KB
testcase_04 AC 26 ms
24,036 KB
testcase_05 AC 29 ms
23,520 KB
testcase_06 AC 29 ms
23,628 KB
testcase_07 AC 25 ms
23,664 KB
testcase_08 AC 31 ms
23,976 KB
testcase_09 AC 24 ms
24,000 KB
testcase_10 AC 453 ms
23,844 KB
testcase_11 AC 1,657 ms
23,796 KB
testcase_12 AC 940 ms
23,520 KB
testcase_13 AC 1,104 ms
23,808 KB
testcase_14 AC 1,514 ms
24,048 KB
testcase_15 AC 1,658 ms
24,012 KB
testcase_16 AC 117 ms
24,264 KB
testcase_17 AC 1,037 ms
23,988 KB
testcase_18 AC 1,412 ms
23,376 KB
testcase_19 AC 1,436 ms
23,520 KB
testcase_20 AC 1,774 ms
24,312 KB
testcase_21 AC 1,763 ms
23,784 KB
testcase_22 AC 1,784 ms
24,180 KB
testcase_23 AC 24 ms
24,312 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<queue>
using namespace std;

bool used[2000][501] = {};
vector<int> arc[501];
int indeg[501] = {};
int n;

void ask(vector<int> &v){
    cout << "?";
    for(int x : v)  cout << " " << x;
    for(int i = 0; i < 2*n-v.size(); i++)   cout << " 0";
    cout << endl << flush;
    char c;
    for(int i = 0; i < n; i++){
        cin >> c;
        if(c == '=')    continue;
        if(c == '<')    arc[v[2*i]].push_back(v[2*i+1]), indeg[v[2*i+1]]++;
        else            arc[v[2*i+1]].push_back(v[2*i]), indeg[v[2*i]]++;
    }
}

void answer(vector<int> &v){
    cout << "!";
    for(int x : v)  cout << " " << x;
    cout << endl << flush;
}

int main(){
    cin >> n;
    vector<int> v[2000];
    for(int i = 1; i <= n; i++){
        for(int j = i+1; j <= n; j++){
            for(int k = 0;;k++){    // TLE?
                if(!used[k][i] && !used[k][j]){
                    used[k][i] = used[k][j] = true;
                    v[k].push_back(i);  v[k].push_back(j);
                    break;
                }
            }
        }
    }
    for(int i = 0; i < 2000; i++){
        if(v[i].size() == 0)    break;
        ask(v[i]);
    }
    vector<int> topo;
    queue<int> q;
    for(int i = 1; i <= n; i++)  if(indeg[i] == 0)   q.push(i);
    while(!q.empty()){
        int x = q.front();  q.pop();
        topo.push_back(x);
        for(int child : arc[x]){
            indeg[child]--;
            if(indeg[child] == 0)   q.push(child);
        }
    }
    answer(topo);
    return 0;
}   
0