QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#50454#2281. BnPCdariusuzumakiRE 3ms3776kbC++112.4kb2022-09-26 07:52:562022-09-26 07:52:57

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-26 07:52:57]
  • 评测
  • 测评结果:RE
  • 用时:3ms
  • 内存:3776kb
  • [2022-09-26 07:52:56]
  • 提交

answer

#include <bits/stdc++.h>
#include <unordered_map>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef double db;
typedef long double ldb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define LI(i, a, b) for (int i = a; i <= b; i++)  // forloop inclusive
#define LE(i, a, b) for (int i = a; i < b; i++)   // forloop exclusive
#define LBI(i, a, b) for (int i = a; i >= b; i--) // forloop backward inclusive
#define LBE(i, a, b) for (int i = a; i > b; i--)  // forloop backward inclusive

#define all(x) begin(x), end(x)
#define Min(a, b) ((a) < (b) ? (a) : (b))
#define Max(a, b) ((a) < (b) ? (b) : (a))

void b()
{
    ll n, k;
    cin >> n >> k;
    unordered_map<string, ll> attr;
    unordered_map<string, vector<ll> > challs;
    string name;
    ll score, res = 0;
    LE(i, 0, n)
    {
        cin >> name >> score;
        attr.insert(pair<string, ll >(name, score));
    }

    cin >> n;
    LE(i, 0, n)
    {
        cin >> name >> score;
        challs[name].push_back(score);
        sort(all(challs[name]));
    }

    for(auto &a : attr) {
        k -= (challs[a.first].back() - a.second > 0) ? challs[a.first].back() - a.second : 0;
        a.second = Max(a.second, challs[a.first].back());
    }

    if (k < 0) {
        cout << 0 << "\n";
        return;
    }

    vector<string> prevs;
    // calculate maximum score
    for(auto a : challs) {
        for(auto i : a.second) {
            if (i == attr[a.first]) {
                break;
            }
            prevs.push_back(a.first);
            res += attr[a.first];
        }
    }

    while (k--) {
        ll h = 0;
        string attribute;
        for (auto a : attr)
        {
            ll np = (find(all(prevs), a.first) != prevs.end()) ? res - (a.second) * (challs[a.first].size() - count(all(challs[a.first]), a.second)) + (a.second + 1) * challs[a.first].size() 
                                            : res + (a.second + 1) * challs[a.first].size();
            if (h < np)
            {
                h = np;
                attribute = a.first;
            }
        }
        prevs.push_back(attribute);
        attr[attribute]++;
        res = h;
    }
    cout << res << "\n";
    return;
}

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

    b();

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 3636kb

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: 0
Accepted
time: 3ms
memory: 3776kb

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:

285180

result:

ok single line: '285180'

Test #4:

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

input:

2 1
A 10
B 12
3
A 10
B 10
B 10

output:

35

result:

ok single line: '35'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3568kb

input:

1 1
OVERENTHUSIASTICNESS 41
1
OVERENTHUSIASTICNESS 0

output:

42

result:

ok single line: '42'

Test #6:

score: -100
Runtime Error

input:

100000 1000000000
A 1000000000
B 1000000000
C 1000000000
D 1000000000
E 1000000000
F 1000000000
G 1000000000
H 1000000000
I 1000000000
J 1000000000
K 1000000000
L 1000000000
M 1000000000
N 1000000000
O 1000000000
P 1000000000
Q 1000000000
R 1000000000
S 1000000000
T 1000000000
U 1000000000
V 1000000...

output:


result: