Codeforces Round 745 Div 2 Editorial Solutions A-C
CQXYM Count Permutations
CQXYM is counting permutations length of
A permutation is an array consisting of distinct integers from to in arbitrary order. For example, is a permutation, but is not a permutation ( appears twice in the array) and is also not a permutation ( but there is in the array).
A permutation (length of ) will be counted only if the number of satisfying is no less than . For example:
- Permutation will count, because the number of such that equals (, , ).
- Permutation won't count, because the number of such that equals ().
CQXYM wants you to help him to count the number of such permutations modulo ().
In addition, modulo operation is to get the remainder. For example:
- , because ,
- , because .
Program Code
Diameter of Graph
CQXYM wants to create a connected undirected graph with nodes and edges, and the diameter of the graph must be strictly less than . Also, CQXYM doesn't want a graph that contains self-loops or multiple edges (i.e. each edge connects two different vertices and between each pair of vertices there is at most one edge).
The diameter of a graph is the maximum distance between any two nodes.
The distance between two nodes is the minimum number of the edges on the path which endpoints are the two nodes.
CQXYM wonders whether it is possible to create such a graph.
The input consists of multiple test cases.
The first line contains an integer — the number of test cases. The description of the test cases follows.
Only one line of each test case contains three integers , ,
For each test case, print YES if it is possible to create the graph, or print NO if it is impossible. You can print each letter in any case (upper or lower).
5 1 0 3 4 5 3 4 6 3 5 4 1 2 1 1
YES NO YES NO NO
Program Code
Portal
CQXYM found a rectangle of size There are rows and columns of blocks. Each block of the rectangle is an obsidian block or empty. CQXYM can change an obsidian block to an empty block or an empty block to an obsidian block in one operation.
A rectangle size of is called a portal if and only if it satisfies the following conditions:
- .
- For all , blocks and are obsidian blocks.
- For all , blocks and are obsidian blocks.
- For all , block is an empty block.
- can be any type.
Note that corners can be any type
CQXYM wants to know the minimum number of operations he needs to make at least one sub-rectangle a portal.
The first line contains an integer (), which is the number of test cases.
For each test case, the first line contains two integers and ( .
Then lines follow, each line contains characters or . If the -th character of -th line is , block is an empty block. Otherwise, block is an obsidian block.
It is guaranteed that the sum of over all test cases does not exceed .
It is guaranteed that the sum of over all test cases does not exceed .
Output answers, and each answer in a line.
1 5 4 1000 0000 0110 0000 0001
12
1 9 9 001010001 101110100 000010011 100000001 101010101 110001111 000001111 111100000 000110000
5
Comments
Post a Comment