21846_Please,gofirs

2022-5-16 18:20| 发布者: Hocassian| 查看: 28| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-4-89505897712900-Problem List-采集的数据-后羿采集器.html

Pro.ID

21846

Title

Please, go first

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=21846

AC

2

Submit

3

Ratio

66.67%

时间&空间限制

  • Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/32768 K (Java/Others)
  • 描述

    You are currently on a skiing trip with a group of friends. In general, it is going well: you enjoy the skiing during the day and, of course, the apres-skiing during the night. However, there is one nuisance: the skiing lift. As always, it is too small, and can only serve one person every 5 seconds. To make matters worse, you and your friends generally don't arrive simultaneously at the lift, which means that you spend time waiting at the bottom of the mountain for the lift and at the top again for your friends.

    The waiting at the top is especially inefficient. In fact, you realize that if your friends haven't arrived yet, you might as well let other people pass you in the queue. For you, it makes no difference, since otherwise you'd be waiting at the top. On the other hand, your actions might save them time if their friends have already arrived and are currently waiting for them at the top.

    You are wondering how much time would be saved if everybody adopts this nice attitude. You have carefully observed the queue for a while and noticed which persons form groups of friends. Suppose someone lets another pass if doing this doesn't change his own total waiting time, but saves time for the other person. Do this over and over again until it can't be done anymore. How much time will this save, in total?

    输入

    On the first line a positive integer: the number of test cases, at most 100. After that per test case:

    • one line with an integer n ( 1 ≤ n ≤ 25000 ): the number of people in the line for the lift.

    • one line with n alphanumeric characters (uppercase and lowercase letters and numbers): the queue. The first person in this line corresponds to the person at the head of the queue. Equal characters correspond to persons from the same group of friends.

    输出

    Description

    You are currently on a skiing trip with a group of friends. In general, it is going well: you enjoy the skiing during the day and, of course, the apres-skiing during the night. However, there is one nuisance: the skiing lift. As always, it is too small, and can only serve one person every 5 seconds. To make matters worse, you and your friends generally don't arrive simultaneously at the lift, which means that you spend time waiting at the bottom of the mountain for the lift and at the top again for your friends.

    The waiting at the top is especially inefficient. In fact, you realize that if your friends haven't arrived yet, you might as well let other people pass you in the queue. For you, it makes no difference, since otherwise you'd be waiting at the top. On the other hand, your actions might save them time if their friends have already arrived and are currently waiting for them at the top.

    You are wondering how much time would be saved if everybody adopts this nice attitude. You have carefully observed the queue for a while and noticed which persons form groups of friends. Suppose someone lets another pass if doing this doesn't change his own total waiting time, but saves time for the other person. Do this over and over again until it can't be done anymore. How much time will this save, in total?

    Input

    On the first line a positive integer: the number of test cases, at most 100. After that per test case:

    • one line with an integer n ( 1 ≤ n ≤ 25000 ): the number of people in the line for the lift.

    • one line with n alphanumeric characters (uppercase and lowercase letters and numbers): the queue. The first person in this line corresponds to the person at the head of the queue. Equal characters correspond to persons from the same group of friends.

    Output

    Per test case:

    one line with an integer: the time saved, in seconds.

    Sample Input

    2
    6
    AABABB
    10
    Ab9AAb2bC2

    Sample Output

    15
    45

    Source

    样例输入

    2
    6
    AABABB
    10
    Ab9AAb2bC2

    样例输出

    15
    45

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部