Skip to content

Commit a2acb5b

Browse files
committed
atcoder/abc157C
1 parent dad1b53 commit a2acb5b

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

atcoder/abc157/C/main.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
using ll = int64_t;
5+
using ff = long double;
6+
7+
int N, M;
8+
vector<int> S, C;
9+
10+
int solve() {
11+
map<int,int> ds;
12+
for (int i = 0; i < M; ++i) {
13+
if (ds.count(S[i]) > 0 && ds[S[i]] != C[i]) return -1;
14+
ds[S[i]] = C[i];
15+
}
16+
if (N == 1) {
17+
return (ds.count(0) > 0 ? ds[0] : 0);
18+
}
19+
if (ds.count(0) > 0 && ds[0] == 0) return -1;
20+
int ans = (ds.count(0) > 0 ? ds[0] : 1);
21+
for (int i = 1; i < N; ++i) {
22+
ans *= 10;
23+
ans += ds[i];
24+
}
25+
return ans;
26+
}
27+
28+
int main() {
29+
ios_base::sync_with_stdio(false);
30+
cin.tie(0); cout.tie(0);
31+
32+
cin >> N >> M;
33+
S.assign(M, 0);
34+
C.assign(M, 0);
35+
for (int i = 0; i < M; ++i) {
36+
cin >> S[i] >> C[i];
37+
--S[i];
38+
}
39+
cout << solve() << endl;
40+
41+
return 0;
42+
}

0 commit comments

Comments
 (0)