結果

問題 No.447 ゆきこーだーの雨と雪 (2)
ユーザー Mister
提出日時 2020-05-29 17:52:28
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 1,612 bytes
コンパイル時間 1,828 ms
コンパイル使用メモリ 101,712 KB
最終ジャッジ日時 2025-01-10 16:14:29
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>

void solve() {
    int n;
    std::cin >> n;

    std::vector<int> xs(n);
    for (auto& x : xs) std::cin >> x;

    std::map<std::string, std::vector<int>> scores;
    std::vector<int> rank(n, 1);

    int q;
    std::cin >> q;

    for (int t = 0; t < q; ++t) {
        std::string s;
        std::cin >> s;

        if (!scores.count(s)) {
            scores[s] = std::vector<int>(n + 1, 0);
        }

        auto& score = scores[s];

        char c;
        std::cin >> c;
        int id = c - 'A';

        auto x = xs[id];
        auto r = rank[id]++;
        score[id] = x * 50 + x * 500 / (r * 2 + 8);
        score.back() = t;
    }

    std::vector<std::pair<std::string, std::vector<int>>> ans(scores.begin(), scores.end());
    std::sort(ans.begin(), ans.end(),
              [](const auto& p, const auto& q) {
                  auto psum = std::accumulate(p.second.begin(), --p.second.end(), 0);
                  auto qsum = std::accumulate(q.second.begin(), --q.second.end(), 0);
                  if (psum != qsum) return psum > qsum;
                  return p.second.back() < q.second.back();
              });

    int id = 1;
    for (auto p : ans) {
        std::cout << id++ << " " << p.first;
        p.second.back() = std::accumulate(p.second.begin(), --p.second.end(), 0);
        for (auto s : p.second) std::cout << " " << s;
        std::cout << "\n";
    }
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}
0