EaglePB2's Competitive Programming Writeups
  • Home Page
  • Why Python?
  • Why 10^9 + 7?
  • General Formatting Title
  • 🇲🇾CodeNection
    • 2021
      • Closed Cateogry
        • Attend Talks
        • Distant Relatives
        • Concert
        • Mamak
        • Fair Contest
      • Open Preliminary Round
        • f(Aibohphobia)^-1
        • Did they cheat?
        • Semester Breaks
      • Open Final Round
        • Ways 1
        • Circular Campus
        • A joke
        • 🥰Last year when life was better
        • Thank You Pizza
    • 2023
      • Test Round
        • Codey and Alphabetical Scoring
        • Codey and Binary Guesser
      • Preliminary Round
        • Codey and CodeNection
        • Codey and Hide-and-Seek
        • Codey and Math
        • Codey and Textbooks
        • Codey and Money
        • Codey and Team Selection
        • Codey and Painted Tree
        • Codey and Number Grid
        • Codey and Crimes
      • Final Round
        • Codey and CodeNection 2
        • Codey and Connection
        • Codey and Schedule
        • Codey and School Supplies
        • Codey and Zombies
        • Codey and Sightseeing
        • Codey and Apples
        • Codey and Facto
        • Codey and Zoey
    • 2024
      • Test Round
        • Codey and Sunday
        • Codey and Takoyaki
      • Preliminary Round
        • Codey and CodeNection
        • Codey and Pebbles
        • Codey and Spam
        • Codey and Coins
        • Codey and Rectangles
        • Codey and Manuscript
        • Codey and Recipes
        • Codey and Toy Kingdom
        • Codey and Peaks
      • Final Round
        • Codey and Exit
        • Codey and Gardening
        • Codey and Symbol
        • Codey and Rectangles 2
        • Codey and Jutsu
        • Codey and Toy Kingdom 2
        • Codey and Speeches
  • ABaKoDa
    • 2023
      • Round 1
        • Problem Letters
        • Problem Statistics
        • Rankings Order
        • Rankings Search
      • Round 2
        • Abakoda Letters
        • Borrowed Words
        • Kensorship
        • Duel Languages
  • Meta Coding Competitions
    • 2011
      • Qualification Round
        • Double Squares
        • Peg Game
        • Studious Student
      • Round 1A
        • Diversity Number
        • Turn on the Lights
        • Wine Tasting
      • Round 1B
        • Chess 2
        • Diminishing Circle
        • Slot Machine Hacker
      • Round 1C
        • N-Factorful
        • Polynomial Factoring
        • Risky Slide
      • Round 2
        • Bonus Assignments
        • Scott's New Trick
        • Studious Student II
      • Final Round
        • Alien Game
        • Party Time
        • Safest Place
  • EaglePB2's Special
    • Hong Kong Identity card
    • Cycle Prefix Averages
    • Word Squares
Powered by GitBook
On this page
  • Question
  • Input Format
  • Constraints
  • Output Format
  • Sample Inputs:
  1. ABaKoDa
  2. 2023
  3. Round 1

Rankings Search

https://codeforces.com/group/cRJbcAFEwS/contest/485694/problem/D

PreviousRankings OrderNextRound 2

Last updated 2 months ago

Question

Abby and Cody want to make a new website called Abakoda, where beginner programmers can join friendly programming contests and improve their skills.

Now they are working on displaying the contest rankings. They want to make a search bar, where a contestant can type their name in, and the rankings will automatically focus on their position in the rankings.

Abby and Cody need your help. In Rankings Order, you figured out together how to display the contestants in order. Now, write a program that processes several requests from contestants to find their position in the rankings.

Input Format

The input contains several lines.

The first line of input contains one integer nnnn, the number of contestants.

This is followed by nnnn lines of input. These lines describe the rankings. These lines will be arranged according to the order described in Rankings Order. Each of these lines contains a name and a score, separated by a space, representing the name and score of a single contestant. The name contains only lowercase English letters, no spaces, and no punctuation marks. Each name contains at least one letter. The score is one of the following: 000, 100100100, 200200200, 300300300, or 400400400.

This is followed by a line containing an integer ssss, the number of search requests.

This is followed by ssss lines of input. Each of these lines contains a name containing only lowercase English letters, no spaces, and no punctuation marks. These names are all names of contestants, which have appeared previously in the part of the input describing the rankings.

Constraints

1≤n≤1051 \le n \le 10^51≤n≤105
  • No two contestants have the same name.

  • The length of each name does not exceed 10.

Output Format

Sample Inputs:

Input

4
abby 400
cody 300
aba 200
koda 100
5
aba
abby
koda
cody
koda

Output

3
1
4
2
4

Explanation:

In the sample test case, there are four contestants, displayed in order.

  • Contestant abby has 400 points.

  • Contestant cody has 300 points.

  • Contestant aba has 200 points.

  • Contestant koda has 100 points.

There are five requests:

Notice that some requests may be duplicated (when a contestant searches their name more than once).


Solution — Simple ranking Pro Max+

Just a continuation of Problem C.

Now we need to create a search function to let participant get their rank.

Here's the solution, anyways:

counter = int(input())
score_list = {}

for i in range(0, counter):
    name, score = input().split()
    score = int(score)
    if name in score_list and score_list[name] < score:
        score_list[name] = score
    elif name not in score_list:
        score_list[name] = score

sorted_scores = sorted(score_list.items(), key=lambda x: (-x[1], x[0]))

ranking = {}
for i, (name, _) in enumerate(sorted_scores, start=1):
    ranking[name] = i

counter_search = int(input())
search = [None] * counter_search

for i in range(0, counter_search):
    search[i] = input()

for name in search:
    if name in ranking:
        print(ranking[name])

1≤s≤1051 \le s \le 10^51≤s≤105

Your program must print sss lines of output. Each line must contain a single integer. The iii-th line of the output must contain the answer to the iii-th search request in the input: the position of a contestant in the rankings. The topmost position in the rankings is position 111.

A request to find contestant aba, who is at position 333.

A request to find contestant abby, who is at position 111.

A request to find contestant koda, who is at position 444.

A request to find contestant cody, who is at position 222.

A request to find contestant koda, who is at position 444.

Page cover image