답안 #1106384

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1106384 2024-10-30T07:56:55 Z SalihSahin Lun (COCI19_lun) C++14
50 / 50
1 ms 504 KB
#include <bits/stdc++.h>
#define pb push_back
#define int long long
using namespace std;

const int mod = 1e9 + 7;
const int inf = 1e17;
const int N = 2e5+5;

int op(int num){
    int x = 0;
    while(num > 0){
        x += num % 10;
        num /= 10;
    }
    return x;
}

int32_t main(){
    cin.tie(0); cout.tie(0);
    ios_base::sync_with_stdio(false);
    int n;
    cin>>n;
    string s;
    cin>>s;
    int ans = -1;

    for(int ch = 0; ch <= 9; ch++){
        int val = 0;
        for(int i = s.size()-2; i >= 0; i -= 2){
            if(s[i] == 'x') val += op(ch * 2);
            else val += op((s[i] - '0') * 2);
        }
        for(int i = s.size()-3; i >= 0; i -= 2){
            if(s[i] == 'x') val += ch;
            else val += (s[i] - '0');
        }

        int check = 0;
        if(s[s.size()-1] == 'x') check = ch;
        else check = s[s.size()-1] - '0';

        if((val * 9)%10 == check){
            ans = ch;
            break;
        }
    }

    cout<<ans<<endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 504 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct