Akari, also known as Light Up, is a logic puzzle played on a rectangular grid. The player places light bulbs in empty cells until the entire grid is illuminated.
A light bulb lights up its own cell and all cells along the horizontal and vertical directions until its light hits an obstacle or the edge of the grid. No two light bulbs should be illuminated by each other. There are clue cells in the original rules indicating exactly how many bulbs must be placed in adjacent cells. However, determining whether a puzzle is solvable has been proven to be NP-complete.
Directions of the light. (a) The light illuminates all cells in the same row or column. (b) The light is blocked by '#' and no longer lights up the '.' cell.
Invalid placement. In this problem, a puzzle without clue cells will be provided for each test case. Please find a solution to the puzzle.
The first line of the input contains two integers $$$N$$$ and $$$M$$$ — the number of rows and columns in the puzzle.
The following $$$N$$$ lines contain the description of the puzzle. Each line contains a string of length $$$M$$$, consisting of characters '.' and '#'. The character '.' denotes an empty cell and the character '#' denotes an obstacle that blocks the light.
Mark the light bulbs you placed with the letter 'L' and output the final configuration in the same format as the given puzzle in the input. If there are multiple solutions, print any of them. It is guaranteed that at least one solution exists for the given input.
3 3....#....
L.. .#L .L.
4 5..#...###...#...#.#.
L.#L. .###L .L#L. .#L#.
Let's define that a string $$$s$$$ is considered better than another string $$$t$$$ if and only if both of the following conditions are met:
Alice has a string $$$s$$$ of length $$$N$$$. She wants to split the string into $$$K$$$ continuous substrings $$$s[1 : p_1], s[p_1 + 1 : p_2], \dots, s[p_{K - 1} + 1 : p_K]$$$ such that:
The first line of input contains a single integer $$$T$$$ denoting the number of test cases.
Each test case consists of a single line containing a lowercase letter string $$$s$$$.
For each test case, output the maximum possible value of $$$K$$$.
2abababaaababaddb
2 4
Maggie discovers a large magical crystal deep within the cave. The crystal has a regular hexagonal shape, which is seen as a symbol of balance. In this world, there are $$$999$$$ types of magic particles. When these particles are arranged in a hexagonal pattern, a crystal is formed. However, if a crystal contains more than one type of particle, it is considered impure and may explode if someone attempts to release its power.
Maggie decides to extract a pure crystal, where all the magic particles are of the same type. For each potential center of the new crystal, help Maggie determine the side length of the largest pure crystal that can be extracted.
![]() | ![]() | ![]() |
| Side length: 1. | Side length: 2. | Not a crystal. |
The first line of the input contains a single integer $$$N$$$ — the side length of the crystal.
The following $$$2N - 1$$$ lines contain the description of the crystal. Each line contains multiple integers $$$a_{r,c}$$$ — the type of the magic particle at the corresponding position.
For each position $$$(r, c)$$$ as the center, output the side length of the largest pure crystal.
Arrange the output in the same format as the given input, and do not output any leading and trailing spaces.
21 11 1 11 1
1 1 1 2 1 1 1
32 1 22 1 2 12 1 1 1 11 1 1 11 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 1 1 1 1
52 8 1 6 28 8 8 1 4 18 8 8 8 4 9 18 8 8 8 8 2 2 38 7 7 8 8 8 2 2 9997 7 7 8 8 8 2 27 7 8 8 8 2 28 8 8 8 2 28 8 8 2 2
1 1 1 1 1 1 1 1 1 1 1 1 2 2 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 2 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 1 1 1 1
Given a set $$$P$$$ of the smallest $$$n$$$ primes $$$p_1 = 2 \le p_2 = 3\le \cdots \le p_n$$$. Partition the primes into two subsets $$$A$$$ and $$$B$$$ (which can be empty), such that the difference between the sums of two subsets is minimized.
Example
If $$$N = 9$$$, the set $$$P$$$ is $$$\{2, 3, 5, 7, 11, 13, 17, 19, 23\}$$$. The table below demonstrates an optimal solution:
| $$$p_1$$$ | $$$p_2$$$ | $$$p_3$$$ | $$$p_4$$$ | $$$p_5$$$ | $$$p_6$$$ | $$$p_7$$$ | $$$p_8$$$ | $$$p_9$$$ | sum | |
| A | 2 | 5 | 7 | 17 | 19 | 50 | ||||
| B | 3 | 11 | 13 | 23 | 50 |
Each test contains multiple test cases. The first line contains a single integer $$$T$$$ — the number of test cases. The description of the test cases follows.
Each test case contains a single integer $$$N$$$ — $$$P$$$ is the set of the smallest $$$N$$$ prime numbers.
For each test case, print a string $$$S$$$ of length $$$N$$$ consisting of characters A and B, representing the optimal partition. If the $$$k$$$-th smallest prime, $$$p_k$$$, belongs to $$$A$$$ in your solution, the $$$k$$$-th character of $$$S$$$ must be A, and it must be B otherwise. If there are multiple such partitions, print any of them.
5344910
AAB ABBA ABBA ABAABABBA BABABABAAB
ICPC Company has $$$N$$$ employees, with employee $$$1$$$ being the boss of the company. Each of the employees numbered $$$2$$$ through $$$N$$$ has a direct supervisor $$$s_i$$$, where $$$1 \leq s_i \lt i$$$. For employee $$$i$$$, all employees $$$s_i, s_{s_i}, \ldots, 1$$$ are considered to be supervisors of employee $$$i$$$.
Now, ICPC Company has a major project that requires sending some employees on a business trip. It is known that selecting the $$$i$$$-th employee will bring a profit of $$$p_i$$$ million dollars (if this value is negative, it means sending that employee on the trip will incur a loss).
However, selecting employees for the trip is not as simple as just choosing those with positive profits. Each employee also has a capability value $$$a_i$$$, where all capability values form a permutation of $$$1$$$ to $$$N$$$. For each employee $$$i$$$ sent on the business trip, if any of their supervisors is not sent, employee $$$i$$$ will need to handle that supervisor's tasks. But if there exists an unsent supervisor's capability value is higher than theirs, employee $$$i$$$ will feel pressure and cause a loss of $$$c_i$$$ million dollars, no matter how many unsent supervisors with higher capability value there are.
Additionally, there is another way losses can occur: for every $$$1 \leq i \lt N$$$, if the employee with capability values $$$i+1$$$ is selected for the trip but the employee with capability values $$$i$$$ is not, a further loss of $$$d_i$$$ million dollars will occur.
But wait! Before ICPC Company decides on the personnel to dispatch, they need to quickly inform the client whether they will accept the project. For this reason, ICPC Company has commissioned you, with your algorithmic expertise, to help them evaluate the maximum potential profit they could achieve.
However, ICPC Company knows an obvious upper bound: the total profit cannot exceed $$$T = \sum_{i=1}^{N}\max(p_i, 0)$$$ million dollars. After careful evaluation, ICPC Company has decided that if the maximum profit from this business trip is less than $$$T - 20$$$ million dollars, they will immediately reject the project; otherwise, they will begin planning for the trip.
Can you help ICPC Company determine whether they should take on the project? If they decide to take on the project, please also output the exact maximum profit that ICPC Company can achieve.
The input first contains a positive integer $$$N$$$, representing the number of employees in ICPC Company.
The next line contains $$$N-1$$$ integers $$$s_2, s_3, \ldots, s_N$$$, where $$$s_i$$$ represents the direct supervisor of the $$$i$$$-th employee.
The third line contains $$$N$$$ integers $$$p_1, p_2, \ldots, p_N$$$, representing the profit the $$$i$$$-th employee can bring.
The fourth line contains $$$N$$$ integers $$$a_1, a_2, \ldots, a_N$$$, representing the capability value of the $$$i$$$-th employee.
The fifth line contains $$$N$$$ integers $$$c_1, c_2, \ldots, c_N$$$, representing the loss parameter of the $$$i$$$-th employee.
The sixth line contains $$$N-1$$$ integers $$$d_1, d_2, \ldots, d_{N-1}$$$, representing the loss parameter between the employees with capability values $$$i$$$ and $$$i+1$$$.
If the maximum profit is less than $$$T - 20$$$ million dollars, output Fail! on a single line. Otherwise, output a single integer representing the maximum profit that ICPC Company can achieve under the optimal strategy for selecting employees to send on the business trip.
41 2 210 -6 6 24 3 2 11 1 1 51 1 1
13
61 2 2 4 4-3 -10 9 -1 4 71 4 3 6 5 20 1 8 1 3 11 5 0 0 2
9
21-42 212 10 420
Fail!
National Taiwan University's campus is quite large, and as a commuting student, Wiwiho doesn't want to walk 15 minutes to her department after a long commute. Therefore, she decides to use the Ubike facilities scattered around the campus.
However, there's a significant flaw she often overlooks. After successfully borrowing a Ubike from a station, she frequently finds that the stations near her department have no available slots when she arrives, forcing her to cycle to a more distant station and then walk a longer distance to her destination, defeating the purpose.
As a competitive programming contestant, Wiwiho decides to plan an optimal route to reach her department as quickly as possible. She selects $$$N$$$ stations on the NTU campus, numbered from $$$1$$$ to $$$N$$$, and plans $$$M$$$ routes between these stations. Each route is defined by three numbers $$$u_i, v_i, w_i$$$, representing a route between station $$$u_i$$$ and $$$v_i$$$ with a cycling time of $$$w_i$$$, regardless of direction.
Because returning a bike depends on luck, for each station, Wiwiho has estimated parameters $$$p_i, q_i, d_i$$$ through statistical data. Initially, all stations are in an "unknown state". When she arrives at station $$$i$$$ which is in an unknown state, she can try to observe the station and use the following strategy:
Besides, when Wiwiho arrives at station $$$i$$$ which is in a full state, she can still choose not to cycle away, and wait an expected $$$q_i$$$ time for a slot to become available, then walk to her department in $$$d_i$$$ time.
Note that Wiwiho can choose not to observe a station when she passes through it.
To simplify the problem, assume that the probabilities and expected values for each station are independent, meaning stations do not influence each other's parameters.
Can you help Wiwiho find the minimum expected time to successfully return a bike and walk to her department if she borrows a Ubike from station $$$1$$$? Note that although Wiwiho can choose to return the bike at station $$$1$$$, she must follow the aforementioned rules, meaning she only has a probability $$$p_1$$$ of immediately returning the bike there.
The first line contains two integers $$$N, M$$$, representing the number of stations, and the number of routes Wiwiho selected.
The second line contains $$$N$$$ floating-point numbers $$$p_1, p_2, \ldots, p_N$$$, representing the probability of finding an available slot at station $$$i$$$ when Wiwiho arrives.
The third line contains $$$N$$$ floating-point numbers $$$q_1, q_2, \ldots, q_N$$$, representing the expected queuing time at station $$$i$$$ if no slot is available upon arrival.
The fourth line contains $$$N$$$ floating-point numbers $$$d_1, d_2, \ldots, d_N$$$, representing the time required to walk from station $$$i$$$ to her department.
The next $$$M$$$ lines each contain two integers and one floating-point number $$$u_i, v_i, w_i$$$, representing a route connecting station $$$u_i$$$ and station $$$v_i$$$, with a cycling time $$$w_i$$$ between them.
Output a single floating-point number representing the minimum expected time for Wiwiho to successfully return a bike and walk to her department after borrowing a Ubike from station $$$1$$$.
Your answer will be accepted if the absolute or relative error does not exceed $$$10^{-6}$$$. Formally, let your answer be $$$a$$$, and the jury's answer be $$$b$$$. Your answer is considered correct if $$$\frac{|a-b|}{\max(1,|b|)}\le 10^{-6}$$$.
4 40.800 0.500 0.200 0.6003.000 3.000 5.000 2.00015.000 5.000 1.000 2.0001 2 3.1412 3 2.7181 3 7.6543 4 1.414
8.78560000000000052012
11 130.800 0.800 0.900 0.900 0.400 0.200 0.200 0.200 0.250 0.400 0.4001.000 2.000 2.000 2.000 3.000 4.000 4.000 4.000 2.000 1.000 1.00015.000 12.000 11.000 9.000 3.000 0.000 0.000 0.000 2.000 5.000 4.0001 2 1.0001 4 2.3332 3 0.3333 4 0.6664 5 2.0005 6 1.0005 10 1.6666 7 0.3336 8 0.3336 9 0.6667 8 0.3339 10 1.0009 11 0.666
7.31551200000000090284
There is a classic graph theory problem: given an undirected graph, find the largest subset of vertices such that the vertices form a clique. A clique is defined as a subset of vertices such that every two distinct vertices are adjacent in the given graph.
However, constructing the graph is troublesome. Now, for the $$$N$$$ vertices in the graph, we assign to the $$$i$$$-th vertex an interval $$$[l, r]$$$, representing a circular interval $$$[l, r]$$$.
What is a circular interval? Suppose the entire circle has a size of $$$2N$$$, which we can represent as coordinates $$$0$$$ to $$$2N-1$$$. A circular interval $$$[l, r]$$$ covers the coordinates: $$$$$$ \begin{cases} l\sim r & \text{if }l \lt r \\ 0\sim r\ \cup\ l\sim 2N-1 & \text{if } l \gt r \end{cases} $$$$$$
where $$$0\leq l, r \lt 2N, l\neq r$$$.
Given these intervals, we let there be an edge between any two vertices if and only if their intervals overlap at some coordinate.
Find any maximum clique.
The first line of input contains a positive integer $$$N$$$, representing the number of intervals.
The next $$$N$$$ lines each contain two integers $$$l_i, r_i$$$, representing the coordinates of the interval for the $$$i$$$-th vertex. The intervals are numbered from $$$0$$$ to $$$N-1$$$.
Output a single integer $$$k$$$ in the first line, representing the size of the maximum clique.
In the second line, output $$$k$$$ integers $$$c_0, c_1, \ldots, c_{k-1}$$$ separated by single spaces, where $$$c_i$$$ represents the index of the intervals included in the maximum clique.
If there are multiple valid solutions, output any one of them.
30 32 54 1
3 0 1 2
50 69 13 45 82 7
3 0 3 4
Boluteshih and 2qbingquan are preparing the problems for Homework 0.514. Boluteshih selected $$$N$$$ problems, while 2qbingquan selected $$$M$$$ problems for the homework.
To make it harder to identify which problems were prepared by whom, Boluteshih wrote a Python script to shuffle the order of these problems randomly. As a coincidence, Boluteshih discovered that after shuffling, the problems chosen by 2qbingquan formed a contiguous subarray within the shuffled list.
Just out of curiosity, you are asked to answer the probability that the problems chosen by 2qbingquan just formed $$$k$$$ contiguous subarray within the shuffled list, for each $$$k$$$ from $$$1$$$ to $$$M$$$. All $$$(N + M)!$$$ permutations of the $$$N + M$$$ problems are considered equiprobable during the shuffle.
As usual, you are asked to output the answer modulo $$$998244353$$$ (see output section).
The input only contains one line with two space-separated integers $$$N, M$$$.
Print $$$M$$$ space-separated integers, where the $$$i$$$-th is the probability of that the problems chosen by 2qbingquan just formed $$$k$$$ contiguous subarray, modulo $$$998244353$$$.
For each $$$k$$$, it can be shown that the probability is in the form of $$$\frac{P}{Q}$$$ where $$$P$$$ and $$$Q$$$ are non-negative integers and $$$Q \neq 0, \mathrm{gcd}(P, Q) = 1$$$. By modulo $$$998244353$$$ it means $$$P\cdot Q^{-1} \pmod{998244353}$$$, which should be an integer in $$$[0, 998244353)$$$.
1 2
665496236 332748118
2 5
855638017 427819009 713031681 0 0
37 9
773088076 617179006 965409427 423633148 606148699 470916699 791168354 947239560 394683150
It's Cody's birthday! This year, instead of giving him a long string or an integer array with special properties, his friends surprised him with an interesting picture. Cody suspects that the image was cropped from a scene in a video he recently watched, but he can't remember the exact timestamp of the frame.
Cody has extracted all the frames in the video by FFmpeg, but he knows little about image matching. You, a helpful coder, decide to handle the task to earn an AC in return. Because the picture is stored in a lossy compression format, it is possible that an exact match cannot be found. The goal is to find a position with the smallest sum of squared difference (SSD) for the best match.
If the size of an image $$$I$$$ is $$$W \times H$$$ and the size of a (smaller) template image $$$T$$$ is $$$N \times M$$$, the SSD value of the position $$$(x, y)$$$ is defined as:
(a) $$$I$$$. (b) $$$T$$$. (c) Image difference. $$$\operatorname{SSD}(1,1) = 3^2 + 6^2 = 45$$$. The first line of the input contains two integers $$$W$$$ and $$$H$$$ — the width and the height of a frame from the video.
The following $$$H$$$ lines contain the description of the image $$$I$$$. Each line contains $$$W$$$ double-digit hexadecimal numbers — the pixels of the corresponding positions.
The next line of the input contains two integers $$$N$$$ and $$$M$$$ — the width and the height of the cropped image.
The following $$$M$$$ lines contain the description of the image $$$T$$$. Each line contains $$$N$$$ double-digit hexadecimal numbers — the pixels of the corresponding positions.
The best matching position $$$(x, y)$$$ $$$(0 \le x \le W - N,\ 0 \le y \le H - M)$$$.
If there are multiple such positions, print any of them.
3 200 FF 12AA BB 342 1FF 11
1 0
4 589 4E 72 C6C7 E9 EA 8F6E B1 FD E47C 22 6C D093 FB DB E53 379 C0 51B9 98 37BB 64 7F
1 0
4 314 59 EF A083 3E AE 9406 AA 0C 873 23E A8 94A7 0C 87
1 1
There is too much work to be done! The ICPC class now has an overwhelming amount of tasks that need to be handled. Each task requires a team of two people to complete. The ICPC class has $$$N$$$ people, and there are $$$M$$$ pairs of people who can work together (assigning incompatible pairs would cause awkwardness and complicate the tasks). Each pair can handle at most one task.
But if you think that means we can handle $$$M$$$ tasks, you are too naive! Each person also has their own workload limit. It is known that the $$$i$$$-th person is willing to handle at most $$$a_i$$$ tasks. This means that if the number of tasks assigned to the $$$i$$$-th person exceeds $$$a_i$$$, that person will refuse to do any work.
Can you help the ICPC class find the maximum number of task-handling pairs, such that no one exceeds their workload limit?
The first line contains two positive integers $$$N$$$ and $$$M$$$, representing the number of people in the ICPC class and the number of pairs who can work together, respectively.
The second line contains $$$N$$$ integers $$$a_1, a_2, \ldots, a_N$$$, where $$$a_i$$$ represents the maximum number of tasks the $$$i$$$-th person is willing to handle.
The next $$$M$$$ lines each contain two integers $$$u_i$$$ and $$$v_i$$$, representing that the $$$u_i$$$-th person and the $$$v_i$$$-th person can work together. The pairs are numbered from $$$1$$$ to $$$m$$$.
The first line should output an integer $$$k$$$, representing the maximum number of task-handling pairs.
The second line should output $$$k$$$ integers $$$w_1, w_2, \ldots, w_k$$$ separated by single spaces, representing an optimal set of pairs that handled $$$k$$$ tasks, where $$$w_i$$$ represents the pair numbered $$$w_i$$$ in your optimal solution.
If there are multiple optimal solutions, any of them will be considered correct.
4 42 1 3 41 21 32 33 4
3 1 2 4
6 82 2 3 2 3 11 21 31 53 53 44 54 65 6
6 1 2 4 5 6 8
Alice and Bob are playing a cool new game called "King Game." The King Game consists of a $$$300 \times 300$$$ board and two pieces that can be placed on certain positions on the board. For convenience, we use 2D coordinates $$$(x, y)$$$ to represent the positions where pieces are placed, where $$$1 \leq x, y \leq 300$$$.
The rules of the King Game are as follows:
Alice and Bob are going to play $$$T$$$ games, and they have already planned the starting coordinates for each game. Can you tell them, for each game, how many winning first moves the "first player" has under the condition that both players play optimally?
The first line contains a positive integer $$$T$$$, representing the number of games.
The next $$$T$$$ lines each contain four integers $$$x_1, y_1, x_2, y_2$$$, representing the starting coordinates of the pieces for one game.
For each game, output a single integer on a new line representing the number of winning first moves the first player has.
51 2 3 43 1 4 26 6 2 23 2 2 31 12 3 9
1 2 2 0 0
Ltf proposed an interesting board game, which is played on an $$$N \times N$$$ board by two players who take turns placing pieces on the board. The unique rule of the game is that each player, when placing a piece, must ensure that no two pieces are orthogonally adjacent, meaning that no two pieces can share a side. The player who cannot place a piece on their turn loses the game.
Ltf invited Ian to play this game with him, and Ltf will go first. Given the size of the board, determine who will win if both players play optimally.
The input consists of a single line containing a positive integer $$$N$$$, representing the size of the board.
If Ltf has a winning strategy, output Ltf on a single line; otherwise, output Ian.
2
Ian
3
Ltf
It's so hot this summer!
Vasya is walking along the street, which can be viewed as an infinite two-dimensional plane. He is currently at the point $$$S = (s_x, s_y)$$$, while an ice cream truck is stationed at the point $$$T = (t_x, t_y)$$$.
Despite his eagerness to get some ice cream, the intense sunshine makes the journey uncomfortable. Fortunately, there are $$$N$$$ shaded areas created by trees and buildings blocking the sun, providing some cooler spots. For the purpose of this problem, these shaded areas are considered as convex polygons.
Vasya aims to find a path to the ice cream truck that minimizes the distance traveled outside these shaded areas. Please determine the minimum length Vasya needs to walk without shade.
The first line is an integer $$$N$$$, denoting the number of shade areas. Then there will be $$$N$$$ sections, each describing a convex polygon.
The $$$i$$$-th section starts with an integer $$$k_i$$$, which is the number of vertices in the $$$i$$$-th shade. Each of the next $$$k_i$$$ lines will be two space-separated integers $$$x_{ij}, y_{ij}$$$, denoting the coordinate of the vertices of the convex polygon. In total, there will be $$$k_i + 1$$$ lines in the $$$i$$$-th section. The vertices will be given in counterclockwise order.
Finally, there will be two lines, each consists of two space-separated integers, $$$s_x, s_y$$$ and $$$t_x, t_y$$$, denoting the coordinate of the starting point and the goal.
Print the desired minimum length.
Your answer will be accepted if the absolute or relative error does not exceed $$$10^{-6}$$$. Formally, let your answer be $$$a$$$, and the jury's answer be $$$b$$$. Your answer is considered correct if $$$\frac{|a-b|}{\max(1,|b|)}\le 10^{-6}$$$.
3310 1020 1020 50330 5090 5070 60390 10100 1090 600 0100 0
34.14213562373095048677
34-80 0-70 -20-50 -25-60 20570 -4090 4070 3060 2050 -103-80 -20100 200 20-100 0100 0
39.40285000290663788153
The exact answer of sample 1 and sample 2 are $$$20 + 10 \sqrt{2}$$$ and $$$20 + \frac{80}{\sqrt{17}}$$$, respectively.
![]() | ![]() |