結果

問題 No.282 おもりと天秤(2)
ユーザー TatamoTatamo
提出日時 2016-06-15 11:36:48
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,683 ms / 5,000 ms
コード長 1,097 bytes
コンパイル時間 396 ms
コンパイル使用メモリ 59,392 KB
実行使用メモリ 24,264 KB
平均クエリ数 212.00
最終ジャッジ日時 2023-09-24 00:08:19
合計ジャッジ時間 16,145 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
23,664 KB
testcase_01 AC 28 ms
24,240 KB
testcase_02 AC 26 ms
23,652 KB
testcase_03 AC 25 ms
23,520 KB
testcase_04 AC 25 ms
23,412 KB
testcase_05 AC 27 ms
23,988 KB
testcase_06 AC 28 ms
24,024 KB
testcase_07 AC 25 ms
23,640 KB
testcase_08 AC 29 ms
23,976 KB
testcase_09 AC 24 ms
23,796 KB
testcase_10 AC 419 ms
23,352 KB
testcase_11 AC 1,423 ms
23,244 KB
testcase_12 AC 440 ms
23,388 KB
testcase_13 AC 697 ms
23,820 KB
testcase_14 AC 1,251 ms
23,424 KB
testcase_15 AC 1,485 ms
23,664 KB
testcase_16 AC 95 ms
23,388 KB
testcase_17 AC 645 ms
23,424 KB
testcase_18 AC 1,048 ms
23,556 KB
testcase_19 AC 1,126 ms
23,364 KB
testcase_20 AC 1,563 ms
23,808 KB
testcase_21 AC 1,683 ms
24,216 KB
testcase_22 AC 1,640 ms
24,264 KB
testcase_23 AC 24 ms
23,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<utility>
#include<algorithm>

using namespace std;

int main(){
	int n;
	cin >> n;

	int *l = new int[n];
	for(int i=0; i<n; i++){
		l[i] = i+1;
	}
	bool flg_all_sorted = false;
	bool flg_all_sorted_prev = false;
	for(int q=0; q<n; q++){ // クエリはn回以内に終了する (while(true)でもいい)
		// send query
		int offset = q%2;
		cout << "? ";
		for(int i=0; i<n; i++){
			if(i*2+2+offset<=n){
				cout << l[i*2+1+offset - 1] << " " << l[i*2+2+offset - 1] << " ";
			}
			else {
				cout << "0 0 ";
			}
		}
		cout << endl; // 出力をflush

		// get answer
		flg_all_sorted_prev = flg_all_sorted;
		flg_all_sorted = true;
		for(int i=0; i<n; i++){
			char tmp;
			cin >> tmp;
			if(tmp == '>'){ // swap
				int index = i*2+1+offset;
				//cerr << "swap " << index << " and " << index+1 << endl;
				swap(l[index - 1], l[index+1 - 1]);
				flg_all_sorted = false;
			}
		}
		if(flg_all_sorted && flg_all_sorted_prev){
			break; // おわり
		}
	}

	// answer
	cout << "! ";
	for(int i=0; i<n; i++){
		cout << l[i] << " ";
	}
	cout << endl;

	return 0;
}
0