We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5c60d81 commit 9cd9141Copy full SHA for 9cd9141
atcoder/abc157/C/main.cpp
@@ -8,21 +8,19 @@ 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];
+ for (int v = 0; v <= 1000; ++v) {
+ string vs = to_string(v);
+ if (vs.size() != N) continue;
+ bool pass = true;
+ for (int i = 0; i < M; ++i) {
+ if (vs[S[i]] != '0' + C[i]) {
+ pass = false;
+ break;
+ }
+ if (pass) return v;
24
}
25
- return ans;
+ return -1;
26
27
28
int main() {
0 commit comments