結果

問題 No.1708 Quality of Contest
ユーザー gazellegazelle
提出日時 2021-10-15 21:50:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 190 ms / 2,000 ms
コード長 5,629 bytes
コンパイル時間 2,120 ms
コンパイル使用メモリ 220,736 KB
実行使用メモリ 57,876 KB
最終ジャッジ日時 2024-09-17 17:25:16
合計ジャッジ時間 6,625 ms
ジャッジサーバーID
(参考情報)
judge6 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
34,968 KB
testcase_01 AC 9 ms
34,968 KB
testcase_02 AC 9 ms
35,328 KB
testcase_03 AC 12 ms
35,644 KB
testcase_04 AC 11 ms
35,352 KB
testcase_05 AC 11 ms
35,228 KB
testcase_06 AC 11 ms
35,480 KB
testcase_07 AC 10 ms
35,384 KB
testcase_08 AC 9 ms
34,964 KB
testcase_09 AC 137 ms
57,876 KB
testcase_10 AC 160 ms
51,144 KB
testcase_11 AC 178 ms
49,920 KB
testcase_12 AC 181 ms
50,456 KB
testcase_13 AC 176 ms
48,900 KB
testcase_14 AC 175 ms
51,240 KB
testcase_15 AC 183 ms
54,540 KB
testcase_16 AC 181 ms
54,072 KB
testcase_17 AC 179 ms
52,476 KB
testcase_18 AC 183 ms
51,676 KB
testcase_19 AC 178 ms
52,976 KB
testcase_20 AC 173 ms
51,284 KB
testcase_21 AC 176 ms
52,512 KB
testcase_22 AC 177 ms
50,968 KB
testcase_23 AC 190 ms
54,388 KB
testcase_24 AC 170 ms
46,916 KB
testcase_25 AC 166 ms
47,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define FOR(i, n, m) for(ll i = (n); i < (ll)(m); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define pb push_back
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
constexpr ll inf = 1000000000;
constexpr ll mod = 998244353;
constexpr long double eps = 1e-6;
 
template<typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2> p) {
    os << to_string(p.first) << " " << to_string(p.second);
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
    REP(i, v.size()) {
        if(i) os << " ";
        os << v[i];
    }
    return os;
}
 
struct modint {
    ll n;
public:
    modint(const ll n = 0) : n((n % mod + mod) % mod) {}
    static modint pow(modint a, int m) {
        modint r = 1;
        while(m > 0) {
            if(m & 1) { r *= a; }
            a = (a * a); m /= 2;
        }
        return r;
    }
    modint &operator++() { *this += 1; return *this; }
    modint &operator--() { *this -= 1; return *this; }
    modint operator++(int) { modint ret = *this; *this += 1; return ret; }
    modint operator--(int) { modint ret = *this; *this -= 1; return ret; }
    modint operator~() const { return (this -> pow(n, mod - 2)); } // inverse
    friend bool operator==(const modint& lhs, const modint& rhs) {
        return lhs.n == rhs.n;
    }
    friend bool operator<(const modint& lhs, const modint& rhs) {
        return lhs.n < rhs.n;
    }
    friend bool operator>(const modint& lhs, const modint& rhs) {
        return lhs.n > rhs.n;
    }
    friend modint &operator+=(modint& lhs, const modint& rhs) {
        lhs.n += rhs.n;
        if (lhs.n >= mod) lhs.n -= mod;
        return lhs;
    }
    friend modint &operator-=(modint& lhs, const modint& rhs) {
        lhs.n -= rhs.n;
        if (lhs.n < 0) lhs.n += mod;
        return lhs;
    }
    friend modint &operator*=(modint& lhs, const modint& rhs) {
        lhs.n = (lhs.n * rhs.n) % mod;
        return lhs;
    }
    friend modint &operator/=(modint& lhs, const modint& rhs) {
        lhs.n = (lhs.n * (~rhs).n) % mod;
        return lhs;
    }
    friend modint operator+(const modint& lhs, const modint& rhs) {
        return modint(lhs.n + rhs.n);
    }
    friend modint operator-(const modint& lhs, const modint& rhs) {
        return modint(lhs.n - rhs.n);
    }
    friend modint operator*(const modint& lhs, const modint& rhs) {
        return modint(lhs.n * rhs.n);
    }
    friend modint operator/(const modint& lhs, const modint& rhs) {
        return modint(lhs.n * (~rhs).n);
    }
};
istream& operator>>(istream& is, modint m) { is >> m.n; return is; }
ostream& operator<<(ostream& os, modint m) { os << m.n; return os; }

using mi = modint;

ll mod_pow(__int128 a, __int128 n, __int128 m = mod) {
    using ll = __int128;
    ll ret = 1;
    ll tmp = a;
    while(n > 0) {
        if(n % 2) ret *= tmp;
        ret %= m;
        tmp = tmp * tmp;
        tmp %= m;
        n /= 2;
    }
    return ret % m;
}

constexpr int MAX_N = 2020202;
mi mod_fact  [MAX_N + 1];
mi mod_fact_i[MAX_N + 1];
mi mod_comb(long long n, long long k) {
    static bool initialized = false;
    if(n < 0 || k < 0 || n < k) return 0;
    if(not initialized) {
        mod_fact[0] = 1;
        for(int i = 1; i <= MAX_N; ++i) {
            mod_fact[i] = i * mod_fact[i - 1];
        }
        mod_fact_i[MAX_N] = mod_pow(mod_fact[MAX_N].n, mod - 2);
        for(int i = MAX_N - 1; i >= 0; --i) {
            mod_fact_i[i] = mod_fact_i[i + 1] * (i + 1);
        }
        initialized = true;
    }
    return mod_fact[n] * mod_fact_i[n - k] * mod_fact_i[k];
}

struct union_find {
    union_find(int n) : par_(n, -1) {}
    void init(int n) { par_.assign(n, -1); }
    int root(int x) { return par_[x] < 0 ? x : par_[x] = root(par_[x]); }
    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if(x == y) return false;
        if(par_[x] < par_[y]) {
            par_[x] += par_[y];
            par_[y] = x;
        } else {
            par_[y] += par_[x];
            par_[x] = y;
        }
        return true;
    }
    bool same(int x, int y) { return root(x) == root(y); }
    int size(int x) { return -par_[root(x)]; }
    vector<int> par_;
};
 
ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
    ll g = gcd(a, b);
    return a / g * b;
}

ll N = 202020;
ll bit[202020];
void add(ll a, ll w) {
	a++;
	for (ll x = a; x <= N; x += x & -x) bit[x] += w;
}
ll sum(ll a) {
	a++;
	ll ret = 0;
	for (ll x = a; x > 0; x -= x & -x) ret += bit[x];
	return ret;
}
// return the sum of [a, b)
ll sum(ll a, ll b) {
	ll ret = 0;
	if(b == 0) return 0;
	ret += sum(b - 1);
	if(a) ret -= sum(a - 1);
	return ret;
}

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

    int n, m, x;
    cin >> n >> m >> x;

    vector<vector<int>> ps(m);

    REP(i, n) {
        int a, b;
        cin >> a >> b;
        ps[b - 1].pb(a);
    }

    vector<ll> cands;
    
    REP(i, m) {
        if(ps[i].empty()) continue;
        sort(ALL(ps[i]));
        cands.pb(ps[i].back() + x);
        REP(j, (int)ps[i].size() - 1) cands.pb(ps[i][j]);
    }

    sort(ALL(cands));
    reverse(ALL(cands));

    ll k;
    cin >> k;

    map<int, int> comp_time;

    REP(i, k) {
        int c;
        cin >> c;
        if(c == 0) comp_time[11451419] += 1;
        else comp_time[c - 1] += 1;
    }

    k -= comp_time[11451419];

    ll ans = 0;

    REP(i, n) {
        ans += k * cands[i];
        k -= comp_time[i];
    }

    cout << ans << endl;

    return 0;
}
0