| UDESC Selection Contest 2024-1 |
|---|
| Finished |
The billionaire explorer Granza, founder of the major space travel company Space-Y, enjoys exploring the Universe aboard his ship, the StarPuma-GTE.
During one of his trips through the Sombrero Galaxy, Granza discovered a planet called Guadalajara. This planet was famous not only for its breathtaking landscapes but also for its enormous casinos and a peculiar card game known as At-Poker.
At-Poker was considered the national pastime of Guadalajara, involving skill, luck, and strategy. On this planet, the casinos are luminous temples where fortunes are made and lost in a matter of rounds. Granza, always a man of challenges, couldn't resist the temptation to participate. As they say in Guadalajara, Granza "jugó fuerte" — he bet high — and unfortunately, his Earth poker skills were of little use against the complex strategies of At-Poker, and he soon found himself without a large part of his fortune.
In At-Poker, $$$N$$$ players numbered from $$$1$$$ to $$$N$$$ are arranged around a circular table in the order $$$1, 2, 3...N$$$, so that for every player $$$i$$$ from $$$1$$$ to $$$N-1$$$, they are to the left of player $$$i+1$$$, and player $$$N$$$ is to the left of player $$$1$$$.
In the game of At-Poker, each player receives a deck of cards represented by a string of lowercase letters and a number $$$G_i$$$. The official rulebook specifies the following:
Rules of At-Poker
Determined not to leave Guadalajara as a loser, Granza set out to learn the strategies of At-Poker. He knew that the only way to return to Earth having recovered his losses would be if he could guarantee a win. To do so, he needed a system that could predict, based on the initial hands of each player, how many points each would score at the end of a round.
The first line of input contains an integer $$$N$$$ $$$(1 \leq N \leq 10^5)$$$, representing the number of players at the table.
The next $$$N$$$ lines describe each player. The $$$i$$$-th line contains a string $$$s_i$$$ $$$(1 \leq |s_i| \leq 10^5)$$$ of lowercase letters (from "a" to "z") and an integer $$$G_i$$$ $$$(0 \leq G_i \leq N-1)$$$. The string $$$s_i$$$ represents player $$$i$$$'s deck, and the integer $$$G_i$$$ indicates how many decks of players to their left are used to form their hand.
The following line contains an integer $$$M$$$ $$$(1 \leq M \leq 10^5)$$$, indicating the number of wildcards available on the table.
The next $$$M$$$ lines list the wildcards. The $$$i$$$-th line contains a string $$$t_i$$$ $$$(1 \leq |t_i| \leq 10^5)$$$ and an integer $$$X_i$$$ $$$(1 \leq X_i \leq 10^9)$$$. The string $$$t_i$$$ is the pattern to look for in the players' hands, and the integer $$$X_i$$$ is the score assigned to this pattern if it is found in a player's hand, ending within their original deck.
It is guaranteed that the sum of the lengths of the strings $$$s_i$$$ and the sum of the lengths of the strings $$$t_i$$$ do not exceed $$$10^5$$$.
The output must consist of a single line containing $$$N$$$ integers separated by spaces, where the $$$i$$$-th value is the score of player $$$i$$$ in the game.
3abd 0dcbca 0dbbca 03ab 3dc 7c 5
3 7 5
5adui 0aba 0gbcaffdf 0abfh 0abbfcafd 08bfc 5fd 4ab 7daduia 16bagbc 12bca 1i 2fh 10
2 7 4 10 7
5adui 2aba 2gbcaffdf 1abfh 0abbfcafd 38bfc 5fd 4ab 7daduia 16bagbc 12bca 1i 2fh 10
2 16 12 10 7
| Name |
|---|


