結果
問題 |
No.3042 拡大コピー
|
ユーザー |
![]() |
提出日時 | 2025-05-14 13:13:00 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,193 bytes |
コンパイル時間 | 231 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 316,844 KB |
最終ジャッジ日時 | 2025-05-14 13:14:01 |
合計ジャッジ時間 | 5,711 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 1 |
other | WA * 1 TLE * 1 -- * 22 |
ソースコード
import sys # Define a function to read input and process def solve(): # Read the number of books (N) # We don't strictly need N if we read until EOF or use readlines, # but reading it first is standard practice. # However, for golfing, reading all lines and slicing is shorter. # Read all lines from standard input starting from the second line # (skipping the first line which contains N). # map(str.split, ...) applies the split() method to each line read. # sys.stdin.readlines() reads all lines, including the trailing newline '\n'. # str.split() handles splitting by whitespace and ignores leading/trailing whitespace, # effectively removing the newline as well. # *L, = ... unpacks the resulting map object into a list L. # Each element of L will be a list like ['title', 'id']. *L,=map(str.split,sys.stdin.readlines()[1:]) # Sort the list L in-place. # The key for sorting is a lambda function that takes an element x from L # (which is a list like ['title', 'id']). # The key function returns a tuple: (x[0], x[1][0]). # x[0] is the title (string). # x[1] is the id (string like "iti", "ni", "san", "yon"). # x[1][0] is the first character of the id ('i', 'n', 's', 'y'). # Python sorts tuples lexicographically. It will first compare the titles (x[0]). # If the titles are the same, it will compare the second element of the key tuple, # which is the first character of the id. # The required order for ids is "iti", "ni", "san", "yon". # Their first characters are 'i', 'n', 's', 'y'. # Since 'i' < 'n' < 's' < 'y' lexicographically, sorting by the first character # correctly implements the secondary sorting criterion for the ids. L.sort(key=lambda x:(x[0],x[1][0])) # Iterate through the sorted list L. # Each element `x` is a list containing the title and id (e.g., ['a', 'iti']). # `print(*x)` uses the splat operator (*) to unpack the list `x`. # `print('a', 'iti')` prints the elements separated by a space, followed by a newline. # This matches the required output format. for x in L:print(*x) # Execute the solve function solve()