結果

問題 No.885 アマリクエリ
ユーザー totori_nyaatotori_nyaa
提出日時 2019-11-29 21:04:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 919 bytes
コンパイル時間 1,507 ms
コンパイル使用メモリ 179,824 KB
実行使用メモリ 9,144 KB
最終ジャッジ日時 2024-04-30 23:04:50
合計ジャッジ時間 3,842 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 198 ms
9,144 KB
testcase_02 AC 82 ms
8,064 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 25 ms
5,376 KB
testcase_06 AC 18 ms
5,376 KB
testcase_07 AC 30 ms
8,192 KB
testcase_08 AC 18 ms
5,376 KB
testcase_09 AC 224 ms
9,140 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 WA -
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
    
    int n;
    cin>>n;
    map<int,int> mp;
    ll sum = 0;
    for(int i=0;i<n;i++){
        int a; cin>>a;
        sum += a;
        mp[a]++;
    }
    int q;
    cin>>q;
    while(q--){
        int a;
        cin>>a;
        vector<int> era;
        vector<int> cnt;
        auto itr = mp.lower_bound(a);
        if(itr == mp.end()){
            cout << sum << "\n";
            continue;
        }
        while(itr != mp.end()){
            era.push_back(itr->first);
            cnt.push_back(itr->second);
            itr++;
        }
        for(int i=0;i<era.size();i++){
            mp.erase(era[i]);
            mp[era[i]%a] += cnt[i];
            sum += (era[i]%a - era[i]) * cnt[i];
        }
        cout << sum << "\n";
    }
}
0