結果

問題 No.282 おもりと天秤(2)
ユーザー tnakao0123tnakao0123
提出日時 2016-04-13 15:35:57
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,460 ms / 5,000 ms
コード長 2,107 bytes
コンパイル時間 797 ms
コンパイル使用メモリ 93,560 KB
実行使用メモリ 24,336 KB
平均クエリ数 284.00
最終ジャッジ日時 2023-09-23 23:47:53
合計ジャッジ時間 15,462 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
24,204 KB
testcase_01 AC 24 ms
24,336 KB
testcase_02 AC 22 ms
24,036 KB
testcase_03 AC 22 ms
24,324 KB
testcase_04 AC 21 ms
23,448 KB
testcase_05 AC 25 ms
23,424 KB
testcase_06 AC 27 ms
24,288 KB
testcase_07 AC 21 ms
24,036 KB
testcase_08 AC 25 ms
23,676 KB
testcase_09 AC 18 ms
24,036 KB
testcase_10 AC 454 ms
24,240 KB
testcase_11 AC 1,296 ms
23,664 KB
testcase_12 AC 523 ms
23,772 KB
testcase_13 AC 706 ms
23,700 KB
testcase_14 AC 1,152 ms
24,216 KB
testcase_15 AC 1,357 ms
24,324 KB
testcase_16 AC 130 ms
24,228 KB
testcase_17 AC 716 ms
24,216 KB
testcase_18 AC 976 ms
24,024 KB
testcase_19 AC 1,014 ms
23,400 KB
testcase_20 AC 1,458 ms
23,604 KB
testcase_21 AC 1,460 ms
23,472 KB
testcase_22 AC 1,431 ms
23,688 KB
testcase_23 AC 21 ms
23,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 282.cc: No.282 おもりと天秤(2) - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 500;

/* typedef */

typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef queue<pii> qpii;

/* global variables */

int cmat[MAX_N][MAX_N], as[MAX_N];
bool used[MAX_N];

/* subroutines */

bool cmpcmat(const int &a, const int &b) { return cmat[a][b] < 0; }

/* main */

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

  qpii aps;
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++) aps.push(pii(i, j));
  
  int n2 = n * 2;

  while (! aps.empty()) {
    //printf("aps=%lu\n", aps.size());
    putchar('?');

    int k = 0;
    vpii qs;
    memset(used, false, sizeof(used));

    while (k < n) {
      bool found = false;
      pii u;

      for (int i = 0; i < aps.size(); i++) {
	u = aps.front(); aps.pop();
	if (! used[u.first] && ! used[u.second]) {
	  found = true;
	  break;
	}
	aps.push(u);
      }

      if (! found) {
	while (k < n) printf(" 0"), k++;
      }
      else {
	used[u.first] = used[u.second] = true;
	printf(" %d %d", u.first + 1, u.second + 1);
	qs.push_back(u);
	k += 2;
      }
    }

    for (int i = 0; i < n; i++) printf(" 0");
    putchar('\n'); cout.flush();

    for (int i = 0; i < n; i++) {
      char ch;
      cin >> ch;

      if (i < qs.size()) {
	int &li = qs[i].first, &ri = qs[i].second;
	int ci = (ch == '<') ? -1 : (ch == '>') ? 1 : 0;
	cmat[li][ri] = ci;
	cmat[ri][li] = -ci;
      }
    }
  }

  //for (int i = 0; i < n; i++) {
  //for (int j = 0; j < n; j++) printf(" %d", cmat[i][j]);
  //putchar('\n');
  //}

  for (int i = 0; i < n; i++) as[i] = i;
  sort(as, as + n, cmpcmat);

  putchar('!');
  for (int i = 0; i < n; i++) printf(" %d", as[i] + 1);
  putchar('\n'); cout.flush();
  return 0;
}
0