QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#49033#2281. BnPCasdasdasfasdfasdfsdafWA 2ms3588kbC++2.6kb2022-09-19 06:48:212022-09-19 06:48:21

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-19 06:48:21]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3588kb
  • [2022-09-19 06:48:21]
  • 提交

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;
}

详细

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'