結果

問題 No.2623 Room Allocation
ユーザー tnakao0123tnakao0123
提出日時 2024-02-16 23:11:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 56 ms / 2,000 ms
コード長 1,202 bytes
コンパイル時間 475 ms
コンパイル使用メモリ 47,552 KB
実行使用メモリ 9,384 KB
最終ジャッジ日時 2024-02-16 23:11:14
合計ジャッジ時間 3,971 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 3 ms
6,676 KB
testcase_06 AC 28 ms
7,900 KB
testcase_07 AC 28 ms
7,900 KB
testcase_08 AC 28 ms
7,900 KB
testcase_09 AC 28 ms
7,900 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 53 ms
9,384 KB
testcase_15 AC 33 ms
6,676 KB
testcase_16 AC 9 ms
6,676 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 34 ms
6,676 KB
testcase_19 AC 32 ms
6,676 KB
testcase_20 AC 34 ms
6,676 KB
testcase_21 AC 34 ms
6,676 KB
testcase_22 AC 26 ms
6,676 KB
testcase_23 AC 16 ms
6,676 KB
testcase_24 AC 33 ms
6,676 KB
testcase_25 AC 28 ms
6,676 KB
testcase_26 AC 4 ms
6,676 KB
testcase_27 AC 56 ms
9,384 KB
testcase_28 AC 21 ms
7,900 KB
testcase_29 AC 11 ms
6,676 KB
testcase_30 AC 56 ms
9,384 KB
testcase_31 AC 4 ms
6,676 KB
testcase_32 AC 5 ms
6,676 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:52:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   52 |     auto [di, ui] = qs[i];
      |          ^
main.cpp:53:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   53 |     auto [dj, uj] = qs[j];
      |          ^
main.cpp:60:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   60 |     auto [di, ui] = qs[i];
      |          ^
main.cpp:64:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   64 |     auto [dj, uj] = qs[j];
      |          ^

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2623.cc:  No.2623 Room Allocation - yukicoder
 */

#include<cstdio>
#include<algorithm>
#include<utility>
 
using namespace std;

/* constant */

const int MAX_N = 200000;
const int MAX_X = 200000;
const int MAX_Y = 200000;
const int MAX_M = MAX_X + MAX_Y;

/* typedef */

typedef long long ll;
typedef pair<ll,int> pli;

/* global variables */

ll ps[MAX_N][2];
pli qs[MAX_N];

/* subroutines */

/* main */

int main() {
  int n, x, y;
  scanf("%d%d%d", &n, &x, &y);
  int m = x + y, k = min(n, m);

  for (int i = 0; i < n; i++) {
    int p;
    char cs[4];
    scanf("%d%s", &p, cs);
    ps[i % m][cs[0] - 'A'] += p;
  }
  
  for (int i = 0; i < k; i++)
    qs[i] = {ps[i][1] - ps[i][0], i};
  sort(qs, qs + k);

  ll sum = 0;
  int i = 0, j = k - 1;
  while (x > 0 && y > 0 && i <= j) {
    auto [di, ui] = qs[i];
    auto [dj, uj] = qs[j];
    if (-di >= dj)
      sum += ps[ui][0], x--, i++;
    else
      sum += ps[uj][1], y--, j--;
  }
  while (x > 0 && i <= j) {
    auto [di, ui] = qs[i];
    sum += ps[ui][0], x--, i++;
  }
  while (y > 0 && i <= j) {
    auto [dj, uj] = qs[j];
    sum += ps[uj][1], y--, j--;
  }

  printf("%lld\n", sum);
  
  return 0;
}
0