結果

問題 No.282 おもりと天秤(2)
ユーザー 小指が強い人小指が強い人
提出日時 2016-01-20 05:24:54
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2,562 ms / 5,000 ms
コード長 1,709 bytes
コンパイル時間 528 ms
コンパイル使用メモリ 57,824 KB
実行使用メモリ 24,228 KB
平均クエリ数 326.96
最終ジャッジ日時 2023-09-23 23:08:04
合計ジャッジ時間 24,988 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
23,868 KB
testcase_01 AC 28 ms
23,664 KB
testcase_02 AC 25 ms
23,496 KB
testcase_03 AC 23 ms
23,268 KB
testcase_04 AC 25 ms
23,868 KB
testcase_05 AC 27 ms
23,664 KB
testcase_06 AC 31 ms
24,108 KB
testcase_07 AC 25 ms
23,364 KB
testcase_08 AC 33 ms
24,216 KB
testcase_09 AC 23 ms
23,616 KB
testcase_10 AC 638 ms
24,000 KB
testcase_11 AC 2,240 ms
23,580 KB
testcase_12 AC 714 ms
23,844 KB
testcase_13 AC 1,113 ms
23,508 KB
testcase_14 AC 1,882 ms
24,204 KB
testcase_15 AC 2,441 ms
23,352 KB
testcase_16 AC 160 ms
23,352 KB
testcase_17 AC 1,042 ms
24,228 KB
testcase_18 AC 1,657 ms
23,328 KB
testcase_19 AC 1,709 ms
23,976 KB
testcase_20 AC 2,562 ms
23,340 KB
testcase_21 AC 2,470 ms
23,868 KB
testcase_22 AC 2,475 ms
23,496 KB
testcase_23 AC 23 ms
23,244 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
using namespace std;

int main(void)
{
    int a[500];
    bool b[500][500] = {0};
    int c[500] = {0};
    int buf[500];
    int n;
    cin >> n;
    for(int i = 0; i < n; i++)
        a[i] = i + 1;
    int offset = 0;
    int count = 0;
    int nn = n * (n - 1) / 2;
    while(count < nn) {
        bool t[500] = {0};
        string str = "?";
        int sc = 0;
        for(int i = 0; i < n; i++) {
            int j = (i + offset + 1) % n;
            if(t[i] || t[j] || b[i][j] || b[j][i])
                continue;
            str += " " + to_string(i + 1) + " " + to_string(j + 1);
            buf[sc * 2] = i;
            buf[sc * 2 + 1] = j;
            count++;
            sc++;
            t[i] = t[j] = b[i][j] = b[j][i] = true;
        }
        offset = (offset + 1) % (n - 1);
        if(sc == 0)
            continue;
        for(int i = sc; i < n; i++)
            str += " 0 0";
        cout << str << endl;
        cout.flush();
        //continue;
        for(int i = 0; i < sc; i++) {
            string s;
            cin >> s;
            if(s[0] == '<')
                c[buf[i * 2 + 1]]++;
            else
                c[buf[i * 2]]++;
        }
        for(int i = sc; i < n; i++) {
            string tmp;
            cin >> tmp;
        }
    }
    string res = "!";
    for(int i = 0; i < n; i++) {
        int m = c[i];
        int k = i;
        for(int j = i + 1; j < n; j++) {
            if(c[j] < m) {
                m = c[j];
                k = j;
            }
        }
        res += " " + to_string(a[k]);
        swap(c[i], c[k]);
        swap(a[i], a[k]);
    }
    cout << res << endl;
    cout.flush();
    return 0;
}
0