結果
| 問題 |
No.885 アマリクエリ
|
| コンテスト | |
| ユーザー |
ngtkana
|
| 提出日時 | 2019-09-13 22:37:49 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,995 bytes |
| コンパイル時間 | 2,581 ms |
| コンパイル使用メモリ | 212,596 KB |
| 最終ジャッジ日時 | 2025-01-07 17:55:23 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 15 WA * 4 |
ソースコード
#include <bits/stdc++.h>
#define loop(n) for (int ngtkana_is_genius = 0; ngtkana_is_genius < int(n); ngtkana_is_genius++)
#define rep(i, begin, end) for(int i = int(begin); i < int(end); i++)
#define all(v) v.begin(), v.end()
#define lint long long
auto cmn = [](auto& a, auto b){if (a > b) {a = b; return true;} return false;};
auto cmx = [](auto& a, auto b){if (a < b) {a = b; return true;} return false;};
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail){
std::cerr << " " << head;
debug_impl(tail...);
}
#define debug(...)\
std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
debug_impl(__VA_ARGS__);\
std::cerr << std::noboolalpha;
template <typename T>
std::istream& operator>> (std::istream& is, std::vector<T>& v) {
for (auto & x : v) is >> x;
return is;
}
template <typename T>
std::ostream& operator<< (std::ostream& os, const std::vector<T>& v) {
auto n = v.size();
os << "{";
for (size_t i = 0; i < n; i++)
{os << (i > 0 ? "," : "") << v.at(i);}
return os << "}";
}
template <typename T, typename U, typename V>
std::ostream& operator<< (std::ostream& os, const std::map<T, U, V>& v) {
for (auto p : v)
{ os << p; }
return os << "}";
}
template <typename T, typename U>
std::ostream& operator<< (std::ostream& os, const std::pair<T, U>& pair)
{ return os << "(" << pair.first << "," << pair.second << ")"; }
template <typename T, typename U>
std::istream& operator>> (std::iostream& is, std::pair<T, U>& pair)
{ return is >> pair.first >> pair.second; }
template<typename T>
class run_length_encoding {
std::vector<std::pair<int, T>> rle;
public:
run_length_encoding(
std::vector<T> input
) :
rle(0)
{
int cnt = 0;
for (auto it = input.begin(); it != input.end(); it++) {
auto jt = next(it); cnt++;
if (jt == input.end() || *it != *jt) {
rle.emplace_back(cnt, *it);
cnt = 0;
}
}
}
auto const& code () const {return rle;}
};
int main() {
std::cin.tie(0); std::cin.sync_with_stdio(false);
int n; std::cin >> n;
std::vector< int > a(n); std::cin >> a;
int q; std::cin >> q;
auto now = std::accumulate(all(a), 0LL);
std::sort(all(a));
auto rle = run_length_encoding< int >(a).code();
std::map< int, int, std::greater< int > > map;
for (auto p : rle) {
map[p.second] = p.first;
}
loop(q) {
int x; std::cin >> x;
while (map.begin() -> first >= x) {
auto p = *map.begin();
map.erase(map.begin());
int cnt, key; std::tie(key, cnt) = p;
auto q = key / x;
auto r = key % x;
now -= q * cnt * x;
auto new_cnt = cnt;
auto new_key = r;
auto it = map.find(new_key);
if (it != map.end()) {
new_cnt += it->second;
map.erase(it);
}
map.insert({new_key, new_cnt});
}
std::cout << now << std::endl;
}
return 0;
}
ngtkana