QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#49033 | #2281. BnPC | asdasdasfasdfasdfsdaf | WA | 2ms | 3588kb | C++ | 2.6kb | 2022-09-19 06:48:21 | 2022-09-19 06:48:21 |
Judging History
answer
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cstring>
#include <functional>
struct action
{
uint64_t name;
int power;
action( uint64_t n, int p )
{
name = n; power = p;
}
};
inline int calculate_score( const std::vector<action>& actions, const std::vector<action>& events )
{
int score = 0;
for( const action& rAction : actions ) {
for( const action& rEvent : events ) {
if( rAction.name != rEvent.name )
continue;
if( rAction.power > rEvent.power )
score += rAction.power;
}
}
return score;
}
int main()
{
int n, k;
std::cin >> n; std::cin >> k;
std::vector<action> action_list;
action_list.reserve( n );
char name[21];
int power;
for( int i = 0; i < n; i++ ) {
std::cin >> name; std::cin >> power;
action_list.emplace_back( std::hash<std::string>{}( name ), power );
}
int l;
std::cin >> l;
std::vector<action> event_list;
event_list.reserve( l );
for( int i = 0; i < l; i++ ) {
char name[21];
std::cin >> name; std::cin >> power;
event_list.emplace_back( std::hash<std::string>{}( name ), power );
}
for( action& rAction : action_list ) {
for( const action& rEvent : event_list ) {
if( rAction.name != rEvent.name )
continue;
if( rAction.power < rEvent.power ) {
int delta = rEvent.power - rAction.power;
rAction.power += delta;
k -= delta;
if( k < 0 ) {
std::cout << 0;
return 0;
}
}
}
}
while( k ) {
int max_effect = 0;
action* best_action = nullptr;
bool duplicates = false;
for( action& rAction : action_list ) {
duplicates = false;
int effect = 0;
for( const action& rEvent : event_list ) {
if( rAction.name != rEvent.name ) {
continue;
}
if( rAction.power == rEvent.power ) {
effect += rAction.power;
duplicates = true;
} else {
effect++;
}
}
if( effect > max_effect ) {
max_effect = effect;
best_action = &rAction;
}
}
if( best_action ) {
best_action->power += 1;
}
if( !duplicates ) {
break;
}
k--;
}
int max_count = 0;
action* most_action = nullptr;
for( action& rAction : action_list ) {
int count = 0;
for( const action& rEvent : event_list ) {
if( rAction.name == rEvent.name ) {
count++;
}
}
if( count > max_count ) {
max_count = count;
most_action = &rAction;
}
}
if( most_action ) {
most_action->power += k;
}
std::cout << calculate_score( action_list, event_list );
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3588kb
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: -100
Wrong Answer
time: 2ms
memory: 3588kb
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:
433
result:
wrong answer 1st lines differ - expected: '429', found: '433'