結果

問題 No.885 アマリクエリ
ユーザー Mr.SpockMr.Spock
提出日時 2020-11-10 19:55:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 736 bytes
コンパイル時間 2,213 ms
コンパイル使用メモリ 212,508 KB
実行使用メモリ 29,488 KB
最終ジャッジ日時 2023-09-30 00:10:10
合計ジャッジ時間 7,283 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 153 ms
4,376 KB
testcase_04 AC 155 ms
4,376 KB
testcase_05 AC 145 ms
4,376 KB
testcase_06 AC 138 ms
4,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 3 ms
4,380 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  int sum = 0;
  map<int, int>m;
  vector<int>v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    sum += v[i];
    m[v[i]]++;
  }
  int q;
  cin >> q;
  set<int>s;
  for (auto k : m) {
    s.insert(k.first);
  }
  int ans = 0;
  for (int i = 0; i < q; i++) {
    int x;
    cin >> x;
    while (*s.rbegin() >= x) {
      int aftermod = (*s.rbegin() % x);
      int cnt = m[*s.rbegin()];
      sum -= (*s.rbegin() - aftermod) * cnt;
      m[*s.rbegin()] = 0;
      s.erase(*s.rbegin());
      s.insert(aftermod);
      m[aftermod] += cnt;
    }
    cout << sum << endl;
  }
}
0