結果

問題 No.2453 Seat Allocation
ユーザー ochiaigawaochiaigawa
提出日時 2023-09-01 22:52:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 157 ms / 2,000 ms
コード長 1,388 bytes
コンパイル時間 2,263 ms
コンパイル使用メモリ 205,312 KB
実行使用メモリ 5,896 KB
最終ジャッジ日時 2023-09-07 15:36:55
合計ジャッジ時間 4,810 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 62 ms
5,612 KB
testcase_06 AC 37 ms
5,368 KB
testcase_07 AC 23 ms
4,376 KB
testcase_08 AC 9 ms
4,376 KB
testcase_09 AC 154 ms
5,620 KB
testcase_10 AC 94 ms
5,896 KB
testcase_11 AC 126 ms
5,608 KB
testcase_12 AC 35 ms
5,288 KB
testcase_13 AC 37 ms
5,356 KB
testcase_14 AC 36 ms
5,336 KB
testcase_15 AC 43 ms
5,456 KB
testcase_16 AC 37 ms
5,268 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 117 ms
5,092 KB
testcase_19 AC 157 ms
5,272 KB
testcase_20 AC 60 ms
4,376 KB
testcase_21 AC 56 ms
4,376 KB
testcase_22 AC 77 ms
5,368 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0); cout.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<int> A(N), B(M);
  for(int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for(int i = 0; i < M; i++) {
    cin >> B[i];
  }
  double ok = 1e-10, ng = 2e9;
  for(int t = 0; t < 100; t++) {
    double m = (ok + ng) / 2;
    int cnt = 0;
    for(int i = 0; i < N; i++) {
      if(cnt >= M) {
        break;
      }
      for(int j = 0; j < M; j++) {
        if(cnt >= M) {
          break;
        }
        if((double) A[i] / B[j] >= m) {
          cnt++;
        } else {
          break;
        }
      }
    }
    if(cnt >= M) {
      ok = m;
    } else {
      ng = m;
    }
  }
  vector<int> a, b, c;
  for(int i = 0; i < N; i++) {
    for(int j = 0; j < M; j++) {
      if((double) A[i] / B[j] >= ok) {
        a.push_back(A[i]);
        b.push_back(B[j]);
        c.push_back(i);
      } else {
        break;
      }
    }
  }
  int sz = a.size();
  vector<int> id(sz);
  for(int i = 0; i < sz; i++) {
    id[i] = i;
  }
  sort(id.begin(), id.end(), [&] (int i, int j) {
    if((long long) a[i] * b[j] == (long long) a[j] * b[i]) {
      return c[i] < c[j];
    } else {
      return (long long) a[i] * b[j] > (long long) a[j] * b[i];
    }
  });
  for(int i = 0; i < M; i++) {
    cout << c[id[i]] + 1 << '\n';
  }
  return 0;
}
0