QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#49381#2281. BnPCkrystofmitkaWA 2ms3636kbC++3.6kb2022-09-20 18:34:502022-09-20 18:34:50

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-09-20 18:34:50]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3636kb
  • [2022-09-20 18:34:50]
  • 提交

answer

#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstring>
#include <list>
#include <cassert>
#include <climits>
#include <bitset>
#include <chrono>
#include <random>
#include <functional>
#include <unordered_map>
#include <unordered_set>

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

typedef long long ll;

#define O(i) i & 1
#define E(i) !O(i)
#define SZ(v) ((int)(v).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n) FORE(i,0,n)
#define FORSZ(i,a,v) FOR(i,a,SZ(v))
#define REPSZ(i,v) REP(i,SZ(v))

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

    ll n; cin >> n;
    ll k; cin >> k;
    unordered_map<string, ll> current;
    unordered_map<string, vector<ll>> maxFreq;
    while (n--) {
        string a; cin >> a;
        ll s; cin >> s;
        current[a] = s;
        maxFreq[a] = vector<ll>(2, 0);
    }

    ll l; cin >> l;
    ll highestFreq = 0;
    vector<pair<string, ll>> thingies;
    while(l--) {
        string a; cin >> a;
        ll t; cin >> t;
        thingies.emplace_back(a,t);

        maxFreq[a][0] = max(maxFreq[a][0], t);
        maxFreq[a][1]++;
        if (maxFreq[a][1] > highestFreq) {
            highestFreq = maxFreq[a][1];
        }
    }

    ll ans = 0;
    priority_queue<ll> q;
    unordered_set<string> mZero;
    for ( const auto &p : current ) {
        vector<ll> mxF = maxFreq[p.first];
        ll diff = p.second - mxF[0];
        if (diff <= 0) {
            k = k + diff;
            if ((mxF[0] + 1) * mxF[1] > highestFreq) {
                q.push((mxF[0] + 1) * mxF[1]);
                mZero.insert(p.first);
            }
        } else if (diff > 0) {
            ans = ans + mxF[0] * mxF[1];
        }
        if (k < 0) {
            cout << '0' << '\n';
            return 0;
        }
    }

    while(k > 0 && !q.empty()) {
        ans = ans + q.top();
        q.pop();
        k--;
    }


    for ( const auto &p : thingies ) {
        if (!mZero.count(p.first)) {
            ll mm = max(maxFreq[p.first][0], current[p.first]);
            ll diff = mm - p.second;
            ans = ans + max(0ll, diff);
        }
    }

    cout << ans + k*highestFreq << '\n';

    return 0;
}



詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 3560kb

input:

3 14
THISISTHEONE 8
B 0
C 0
8
THISISTHEONE 10
C 0
B 1
B 0
THISISTHEONE 0
C 1
THISISTHEONE 0
THISISTHEONE 0

output:

82

result:

ok single line: '82'

Test #2:

score: 0
Accepted
time: 2ms
memory: 3540kb

input:

3 99
THEFIRSTINCREASE 6
SECONDINCREASE 4
ZZZ 1
9
THEFIRSTINCREASE 4
ZZZ 0
THEFIRSTINCREASE 6
SECONDINCREASE 8
THEFIRSTINCREASE 2
SECONDINCREASE 1
ZZZ 0
SECONDINCREASE 8
THEFIRSTINCREASE 3

output:

429

result:

ok single line: '429'

Test #3:

score: -100
Wrong Answer
time: 2ms
memory: 3636kb

input:

5 20
A 100
B 200
C 300
D 400
E 500
949
A 39
A 23
C 163
A 98
B 36
A 3
A 52
B 152
B 167
B 65
C 142
B 66
B 117
C 288
C 155
E 341
A 97
D 173
E 31
A 62
D 90
E 361
A 42
D 85
E 1
C 141
B 77
B 194
D 221
E 203
D 345
E 48
B 26
D 46
B 74
E 380
B 181
C 243
B 112
A 99
E 403
C 20
E 453
C 149
B 26
E 245
A 74
D 304...

output:

427881

result:

wrong answer 1st lines differ - expected: '285180', found: '427881'