C - Guess The Number
Editorial
/
Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 300 点
問題文
以下の条件を満たす 0 以上の整数が存在すれば、それらのうち最小のものを出力してください。そのような整数が存在しなければ、 -1
と出力してください。
- 十進表記で丁度 N 桁である。(0 は 1 桁の整数とする。その他の整数については、先頭に 0 をつけた表記は認めない。)
- 左から数えて s_i 桁目は c_i である。\left(i = 1, 2, \cdots, M\right)
制約
- 入力は全て整数
- 1 \leq N \leq 3
- 0 \leq M \leq 5
- 1 \leq s_i \leq N
- 0 \leq c_i \leq 9
入力
入力は以下の形式で標準入力から与えられる。
N M s_1 c_1 \vdots s_M c_M
出力
答えを出力せよ。
入力例 1
3 3 1 7 3 2 1 7
出力例 1
702
702 の左から 1 桁目は 7
であり、 3 桁目は 2
ですから、 702 は問の条件を満たします。また、 701 以下の非負整数は問の条件を満たしません。
入力例 2
3 2 2 1 2 3
出力例 2
-1
入力例 3
3 1 1 0
出力例 3
-1
Score : 300 points
Problem Statement
If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print -1
.
- The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.)
- The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right)
Constraints
- All values in input are integers.
- 1 \leq N \leq 3
- 0 \leq M \leq 5
- 1 \leq s_i \leq N
- 0 \leq c_i \leq 9
Input
Input is given from Standard Input in the following format:
N M s_1 c_1 \vdots s_M c_M
Output
Print the answer.
Sample Input 1
3 3 1 7 3 2 1 7
Sample Output 1
702
702 satisfies the conditions - its 1-st and 3-rd digits are 7
and 2
, respectively - while no non-negative integer less than 702 satisfies them.
Sample Input 2
3 2 2 1 2 3
Sample Output 2
-1
Sample Input 3
3 1 1 0
Sample Output 3
-1