AtCoder Beginner Contest 157 C.Guess The Number

81 篇文章 1 订阅

AtCoder Beginner Contest 157 C.Guess The Number

题目链接

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 si-th digit from the left is ci. (i=1,2,⋯,M)

Constraints

All values in input are integers.

  • 1 ≤ N ≤ 3 1≤N≤3 1N3
  • 0 ≤ M ≤ 5 0≤M≤5 0M5
  • 1 ≤ s i ≤ N 1≤s_i≤N 1siN
  • 0 ≤ c i ≤ 9 0≤c_i≤9 0ci9

Input

Input is given from Standard Input in the following format:

N   M N M N M
s 1   c 1 s_1 c_1 s1 c1

s M   c M s_M c_M sM cM

Output

Print the answer.

Sample Input 1

3 3
1 7
3 2
1 7

Sample Output 1

702
702

Sample Input 2

3 2
2 1
2 3

Sample Output 2

-1

Sample Input 3

3 1
1 0

Sample Output 3

-1

自认为是最坑的一次ABC了,因为和cf冲突,做得比较急,还wa了三发,我把坑点罗列一下,供各位参考:
1. n = 1 , m = 0 n=1,m=0 n=1,m=0 时,输出 0 0 0
2.当 s i = 1 , c i = 0 s_i=1,c_i=0 si=1,ci=0 时,存在前导 0 0 0 ,输出 − 1 -1 1
3.当对一个位置赋不同值时,输出 − 1 -1 1
4.最难想的,当 n > 1 n>1 n>1 时,第一个位置未赋值,比如:

3 1
2 0

应该输出100,也即首位未赋值时要补1
5.未赋值的位置补0或1
就不在代码里挂注释了,AC代码如下:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
    int n,m,a[10],s,c;
    map<int,int>q;
    cin>>n>>m;
    int flag=1;
    memset(a,-1,sizeof(a));
    while(m--){
        cin>>s>>c;
        if(q.count(s)==0){
            q[s]=c;
            a[s]=c;
        }
        else{
            if(q[s]!=c) flag=0;
        }
    }
    if(a[1]==0 && n>1) flag=0;
    if(flag==0) puts("-1");
    else{
        if(n>1){
            for(int i=1;i<=n;i++){
                if(a[i]==-1 && i==1) cout<<1;
                else if(a[i]==-1 && i>1) cout<<0;
                else cout<<a[i];
            }
        }
        else{
            if(a[1]==-1) cout<<0;
            else cout<<a[1];
        }
    }
    return 0;
}
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

旺 崽

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值