結果

問題 No.885 アマリクエリ
ユーザー mdstoymdstoy
提出日時 2019-09-14 18:12:00
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 467 ms / 2,000 ms
コード長 1,291 bytes
コンパイル時間 1,615 ms
コンパイル使用メモリ 175,452 KB
実行使用メモリ 16,684 KB
最終ジャッジ日時 2023-09-20 11:08:21
合計ジャッジ時間 5,400 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 185 ms
4,380 KB
testcase_01 AC 437 ms
16,684 KB
testcase_02 AC 259 ms
9,612 KB
testcase_03 AC 212 ms
4,376 KB
testcase_04 AC 214 ms
4,376 KB
testcase_05 AC 191 ms
4,380 KB
testcase_06 AC 164 ms
4,380 KB
testcase_07 AC 67 ms
9,800 KB
testcase_08 AC 173 ms
4,376 KB
testcase_09 AC 467 ms
16,172 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 5 ms
4,376 KB
testcase_14 AC 5 ms
4,376 KB
testcase_15 AC 5 ms
4,380 KB
testcase_16 AC 4 ms
4,380 KB
testcase_17 AC 4 ms
4,376 KB
testcase_18 AC 4 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define ALL(c) (c).begin(), (c).end()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    map<ll, ll> m;
    ll t = 0;
    ll a;
    REP(i, n) {
        cin >> a;
        t += a;
        m[a]++;
    }

    int q;
    cin >> q;
    ll x;
    REP(i, q) {
        ll s = t;
        vector<ll> r;
        cin >> x;
        for (auto itr = m.rbegin(); itr != m.rend(); itr++) {
            if (itr->first >= x) {
                ll y = itr->first % x;
                if (y == 0) {
                    s -= itr->first * itr->second;
                } else {
                    s -= (itr->first - y) * itr->second;
                    m[y] += itr->second;
                }
                r.push_back(itr->first);
            } else {
                break;
            }
        }
        cout << s << endl;
        t = s;
        for (auto z : r) {
            m.erase(z);
        }
    }
}
0