Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
英小文字からなる文字列 S が与えられます。
S に a が現れるならば最後に現れるのが何文字目かを出力し、現れないならば -1 を出力してください。
制約
- S は英小文字からなる長さ 1 以上 100 以下の文字列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
答えを出力せよ。
入力例 1
abcdaxayz
出力例 1
7
S に a は 3 回現れますが、最後に現れるのは 7 文字目なので、7 を出力します。
入力例 2
bcbbbz
出力例 2
-1
S に a は現れないので、-1 を出力します。
入力例 3
aaaaa
出力例 3
5
Score : 100 points
Problem Statement
You are given a string S consisting of lowercase English letters.
If a appears in S, print the last index at which it appears; otherwise, print -1. (The index starts at 1.)
Constraints
- S is a string of length between 1 and 100 (inclusive) consisting of lowercase English letters.
Input
The input is given from Standard Input in the following format:
S
Output
Print the answer.
Sample Input 1
abcdaxayz
Sample Output 1
7
a appears three times in S. The last occurrence is at index 7, so you should print 7.
Sample Input 2
bcbbbz
Sample Output 2
-1
a does not appear in S, so you should print -1.
Sample Input 3
aaaaa
Sample Output 3
5
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
高橋くんと青木くんが N 回の試合を行いました。
これらの試合の結果を表す長さ N の文字列 S が与えられます。
i 回目の試合の勝者は、S の i 文字目が T ならば高橋くん、A ならば青木くんです。
高橋くんと青木くんのうち、勝った試合の数が多い方を総合勝者とします。 ただし、勝った試合の数が同じである場合は、先にその勝ち数に達した者を総合勝者とします。 高橋くんと青木くんのどちらが総合勝者であるか求めてください。
制約
- 1\leq N \leq 100
- N は整数
- S は
TおよびAからなる長さ N の文字列
入力
入力は以下の形式で標準入力から与えられる。
N S
出力
総合勝者が高橋くんならば T を、青木くんならば A を出力せよ。
入力例 1
5 TTAAT
出力例 1
T
高橋くんは 3 回の試合に勝ち、青木くんは 2 回の試合に勝ちました。 よって、勝った試合の数が多い高橋くんが総合勝者です。
入力例 2
6 ATTATA
出力例 2
T
高橋くんと青木くんのどちらも 3 回の試合に勝ちました。 また、高橋くんは 5 回目の試合で 3 勝目に達し、青木くんは 6 回目の試合で 3 勝目に達しました。 よって、先に 3 勝目に達した高橋くんが総合勝者です。
入力例 3
1 A
出力例 3
A
Score : 100 points
Problem Statement
Takahashi and Aoki played N games.
You are given a string S of length N, representing the results of these games.
Takahashi won the i-th game if the i-th character of S is T, and Aoki won that game if it is A.
The overall winner between Takahashi and Aoki is the one who won more games than the other. If they had the same number of wins, the overall winner is the one who reached that number of wins first. Find the overall winner: Takahashi or Aoki.
Constraints
- 1\leq N \leq 100
- N is an integer.
- S is a string of length N consisting of
TandA.
Input
The input is given from Standard Input in the following format:
N S
Output
If the overall winner is Takahashi, print T; if it is Aoki, print A.
Sample Input 1
5 TTAAT
Sample Output 1
T
Takahashi won three games, and Aoki won two. Thus, the overall winner is Takahashi, who won more games.
Sample Input 2
6 ATTATA
Sample Output 2
T
Both Takahashi and Aoki won three games. Takahashi reached three wins in the fifth game, and Aoki in the sixth game. Thus, the overall winner is Takahashi, who reached three wins first.
Sample Input 3
1 A
Sample Output 3
A
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
正整数 X が与えられます。
X を(先頭に 0 を含まない形で)十進表記した際に現れる数字を、先頭に 0 が来ないように 並び替えることで得られる正整数のうち、値が最小のものを求めてください。
制約
- 1\leq X < 10^5
- X は整数
入力
入力は以下の形式で標準入力から与えられる。
X
出力
答えを出力せよ。
入力例 1
903
出力例 1
309
X を十進表記した際に現れる数字を先頭に 0 が来ないように並び替えることで得られる正整数は、903, 930, 309, 390 の 4 通りであり、このうち値が最小のものは 309 です。
入力例 2
432
出力例 2
234
入力例 3
100
出力例 3
100
Score : 200 points
Problem Statement
You are given a positive integer X.
Find the minimum value among all positive integers that can be obtained by rearranging the digits appearing in the decimal representation of X (without leading zeros) such that there is no leading zero.
Constraints
- 1\leq X < 10^5
- X is an integer.
Input
The input is given from Standard Input in the following format:
X
Output
Output the answer.
Sample Input 1
903
Sample Output 1
309
There are four positive integers that can be obtained by rearranging the digits appearing in the decimal representation of X such that there is no leading zero: 903, 930, 309, 390; the minimum value among them is 309.
Sample Input 2
432
Sample Output 2
234
Sample Input 3
100
Sample Output 3
100
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
人 1,2,\dots,N ( N は奇数 ) が、 M 回の 0 か 1 かを選択する投票を行いました。
各人の各回の投票は N 個の長さ M の 0, 1 からなる文字列 S_1,S_2,\dots,S_N として与えられ、 S_i の j 文字目は人 i の j 回目の投票への内容を表します。
各回の投票で、少数派であった人は 1 点を得ます。
より厳密には、次のルールで得点が与えられます。
- その回の投票で
0を選択した人が x 人、1を選択した人が y 人いたとします。- x=0 または y=0 である場合、その投票では全員に 1 点が与えられる。
- そうでなく x<y である場合、その投票で
0に投票した人のみに 1 点が与えられる。 - そうでない場合、その投票で
1に投票した人のみに 1 点が与えられる。 - なお、 N が奇数であることから x=y となることはないことに留意してください。
M 回の投票を終えた後、それらの投票における合計の得点が最も高い人を全員求めてください。
制約
- N は 1 \le N \le 99 を満たす 奇数
- M は 1 \le M \le 100 を満たす整数
- S_i は長さ M の
0,1からなる文字列
入力
入力は以下の形式で標準入力から与えられる。
N M S_1 S_2 \vdots S_N
出力
得点が最も高い人の番号を全て、 番号の昇順に 空白区切りで出力せよ。
入力例 1
3 5 11100 10101 01110
出力例 1
2 3
このケースでは、 3 人が 5 回の投票を行いました。
- 1 回目の投票では人 1 が
1、人 2 が1、人 3 が0に投票しました。よって、人 3 のみが 1 点を得ます。 - 2 回目の投票では人 1 が
1、人 2 が0、人 3 が1に投票しました。よって、人 2 のみが 1 点を得ます。 - 3 回目の投票では人 1 が
1、人 2 が1、人 3 が1に投票しました。よって、全員が 1 点を得ます。 - 4 回目の投票では人 1 が
0、人 2 が0、人 3 が1に投票しました。よって、人 3 のみが 1 点を得ます。 - 5 回目の投票では人 1 が
0、人 2 が1、人 3 が0に投票しました。よって、人 2 のみが 1 点を得ます。
この結果、人 1 は合計 1 点、人 2 は合計 3 点、人 3 は合計 3 点を得ました。
よって、人 2,3 が合計の得点が最も高い人です。これらを番号の昇順に出力してください。
入力例 2
5 4 0000 0000 0000 0000 0000
出力例 2
1 2 3 4 5
入力例 3
7 8 11010011 01000000 01111100 10111000 10011110 10100101 10010110
出力例 3
1 2 3
Score : 200 points
Problem Statement
People 1,2,\dots,N (where N is odd) conducted M votes where each person chooses either 0 or 1.
Each person's vote for each round is given as N strings S_1,S_2,\dots,S_N of length M consisting of 0 and 1, where the j-th character of S_i represents person i's vote content for the j-th vote.
In each vote, people who were in the minority receive 1 point.
More precisely, points are given according to the following rules:
- Suppose x people chose
0and y people chose1in that vote.- If x=0 or y=0, everyone receives 1 point for that vote.
- Otherwise, if x<y, only people who voted
0in that vote receive 1 point. - Otherwise, only people who voted
1in that vote receive 1 point. - Note that since N is odd, x=y never occurs.
After finishing M votes, find all people who have the highest total score from those votes.
Constraints
- N is an odd number satisfying 1 \le N \le 99.
- M is an integer satisfying 1 \le M \le 100.
- S_i is a string of length M consisting of
0and1.
Input
The input is given from Standard Input in the following format:
N M S_1 S_2 \vdots S_N
Output
Output all person numbers with the highest score in ascending order of person number, separated by spaces.
Sample Input 1
3 5 11100 10101 01110
Sample Output 1
2 3
In this case, three people conducted five votes.
- In the 1st vote, person 1 voted
1, person 2 voted1, person 3 voted0. Thus, only person 3 receives 1 point. - In the 2nd vote, person 1 voted
1, person 2 voted0, person 3 voted1. Thus, only person 2 receives 1 point. - In the 3rd vote, person 1 voted
1, person 2 voted1, person 3 voted1. Thus, everyone receives 1 point. - In the 4th vote, person 1 voted
0, person 2 voted0, person 3 voted1. Thus, only person 3 receives 1 point. - In the 5th vote, person 1 voted
0, person 2 voted1, person 3 voted0. Thus, only person 2 receives 1 point.
As a result, person 1 received a total of 1 points, person 2 received a total of 3 points, and person 3 received a total of 3 points.
Therefore, persons 2 and 3 have the highest total score. Output these in ascending order of person number.
Sample Input 2
5 4 0000 0000 0000 0000 0000
Sample Output 2
1 2 3 4 5
Sample Input 3
7 8 11010011 01000000 01111100 10111000 10011110 10100101 10010110
Sample Output 3
1 2 3
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
上下左右に広がる N\times N のマス目があり、最初全てのマスは白く塗られています。このマス目の上から i 行目、左から j 列目のマスを (i,j) で表します。
高橋君は 1 以上 N 以下の整数 A, B を持っており、次のような操作を行います。
- \max(1-A,1-B)\leq k\leq \min(N-A,N-B) をみたす全ての整数 k について、(A+k,B+k) を黒く塗る。
- \max(1-A,B-N)\leq k\leq \min(N-A,B-1) をみたす全ての整数 k について、(A+k,B-k) を黒く塗る。
この操作を行った後のマス目について、P\leq i\leq Q かつ R\leq j\leq S をみたす各マス (i,j) がそれぞれ何色で塗られているか求めてください。
制約
- 1 \leq N \leq 10^{18}
- 1 \leq A \leq N
- 1 \leq B \leq N
- 1 \leq P \leq Q \leq N
- 1 \leq R \leq S \leq N
- (Q-P+1)\times(S-R+1)\leq 3\times 10^5
- 入力は全て整数である。
入力
入力は以下の形式で標準入力から与えられる。
N A B P Q R S
出力
Q-P+1 行出力せよ。
各行は # と . のみからなる長さ S-R+1 の文字列であり、
i 行目の文字列の j 番目の文字が
# であることは (P+i-1,R+j-1) が黒く塗られていることを、
. であることは (P+i-1,R+j-1) が白く塗られていることをさす。
入力例 1
5 3 2 1 5 1 5
出力例 1
...#. #.#.. .#... #.#.. ...#.
1 つめの操作で (2,1), (3,2), (4,3), (5,4) の 4 マスが、
2 つめの操作で (4,1), (3,2), (2,3), (1,4) の 4 マスが黒く塗られます。
よって、P=1, Q=5, R=1, S=5 より、上のように出力します。
入力例 2
5 3 3 4 5 2 5
出力例 2
#.#. ...#
操作によって、
(1,1), (1,5), (2,2), (2,4), (3,3), (4,2), (4,4), (5,1), (5,5) の 9 マスが
黒く塗られます。
P=4, Q=5, R=2, S=5 より、上のように出力します。
入力例 3
1000000000000000000 999999999999999999 999999999999999999 999999999999999998 1000000000000000000 999999999999999998 1000000000000000000
出力例 3
#.# .#. #.#
入力が 32 bit 整数型に収まらないことがあることに注意してください。
Score : 300 points
Problem Statement
There is an N\times N grid with horizontal rows and vertical columns, where all squares are initially painted white. Let (i,j) denote the square at the i-th row and j-th column.
Takahashi has integers A and B, which are between 1 and N (inclusive). He will do the following operations.
- For every integer k such that \max(1-A,1-B)\leq k\leq \min(N-A,N-B), paint (A+k,B+k) black.
- For every integer k such that \max(1-A,B-N)\leq k\leq \min(N-A,B-1), paint (A+k,B-k) black.
In the grid after these operations, find the color of each square (i,j) such that P\leq i\leq Q and R\leq j\leq S.
Constraints
- 1 \leq N \leq 10^{18}
- 1 \leq A \leq N
- 1 \leq B \leq N
- 1 \leq P \leq Q \leq N
- 1 \leq R \leq S \leq N
- (Q-P+1)\times(S-R+1)\leq 3\times 10^5
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N A B P Q R S
Output
Print Q-P+1 lines.
Each line should contain a string of length S-R+1 consisting of # and ..
The j-th character of the string in the i-th line should be # to represent that (P+i-1, R+j-1) is painted black, and . to represent that (P+i-1, R+j-1) is white.
Sample Input 1
5 3 2 1 5 1 5
Sample Output 1
...#. #.#.. .#... #.#.. ...#.
The first operation paints the four squares (2,1), (3,2), (4,3), (5,4) black, and the second paints the four squares (4,1), (3,2), (2,3), (1,4) black.
Thus, the above output should be printed, since P=1, Q=5, R=1, S=5.
Sample Input 2
5 3 3 4 5 2 5
Sample Output 2
#.#. ...#
The operations paint the nine squares (1,1), (1,5), (2,2), (2,4), (3,3), (4,2), (4,4), (5,1), (5,5).
Thus, the above output should be printed, since P=4, Q=5, R=2, S=5.
Sample Input 3
1000000000000000000 999999999999999999 999999999999999999 999999999999999998 1000000000000000000 999999999999999998 1000000000000000000
Sample Output 3
#.# .#. #.#
Note that the input may not fit into a 32-bit integer type.