[Solution] Sort the Fabrics Round F 2022 - Kick Start 2022 Solution
Problem
A fabric is represented by three properties:
- Color (), a string consisting of lowercase letters of the English alphabet, representing the color of the fabric.
- Durability (), an integer representing the durability of the fabric.
- Unique identifier (), an integer representing the ID of the fabric.
Ada and Charles work at the Kick Start fabric factory. Each day they receive fabrics, and one of them has to sort it. They sort it using the following criteria:
- Ada sorts in lexicographically increasing order by color ().
- Charles sorts in ascending order by durability ().
- They break ties by sorting in ascending order by the unique identifier ().
Given fabrics, count the number of fabrics which end up in the same position regardless of whether Ada or Charles sort them.
Input
The first line of the input gives the number of test cases, . test cases follow.
Each test case begins with one line consisting of an integer denoting the number of fabrics. Then lines follow, each line with a string , an integer , and an integer : the color, the durability and the unique identifier of the -th fabric respectively.
Output
For each test case, output one line containing Case #:
, where is the test case number (starting from 1) and is the number of fabrics which end up in the same position regardless of whether a worker sorts them by color or by durability.
Limits
Time limit: 20 seconds.
Memory limit: 1 GB.
.
length of string .
String consists of only lowercase letters of the English alphabet.
No two fabrics have same .
Test Set 1
.
.
.
Test Set 2
.
.
.
In Sample Case #1, when sorted by color, the order of fabrics represented by the unique identifier is and . When sorted by durability, the order of fabrics is and . Therefore, fabrics have the same position when sorted by color or durability.
In Sample Case #2, when sorted by color, the order of fabrics represented by the unique identifier is and . When sorted by durability, the order of fabrics is also and . Therefore, fabrics have the same position. Notice that both fabrics have the same durability, so when Charles sorts them he decides that fabric comes first because it has a smaller identifier.
In Sample Case #3, since there is only fabric, the position remains the same whether the fabrics are sorted by color or durability.
No comments:
Post a Comment