#include <bits/stdc++.h>
using namespace std;
bool valid(string const& s) {
auto f = [](int x) {
if (x >= 10) return x/10+x%10;
return x;
};
int acc = 0;
for (int i = (int)s.size()-2; i >= 0; i--) {
int x = s[i]-'0';
if ((s.size()-1-i)&1) acc += f(2*x);
else acc += x;
}
acc = acc*9%10;
return acc == s.back()-'0';
}
int main() {
int n;
cin >> n;
string s;
cin >> s;
int xpos = 0;
for (int i = 0; i < n; i++) {
if (s[i] >= '0' and s[i] <= '9') continue;
xpos = i;
}
for (int i = '0'; i <= '9'; i++) {
s[xpos] = i;
if (valid(s)) {
cout << char(i) << "\n";
return 0;
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |