답안 #377148

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
377148 2021-03-13T04:40:58 Z marat0210 Lun (COCI19_lun) C++14
15 / 50
1 ms 364 KB
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    string s;
    cin >>n>>s;
    long long sum = 0;
    for (int i = 0; i < n; ++i) {
        if (i % 2 == 1 and s[i] != 'x') {
            long long k = (s[i] - '0') * 2;
            if (k > 9) {
                sum += (1 + k % 10);
            }
            else {
                sum += k;
            }
        }
        else {
            if (s[i] != 'x') {
                sum += (s[i] - '0');
            }
        }
    }
    if (s[n - 1] == 'x') {
        cout <<(sum * 9) % 10<<endl;
    }
    else {
        long long pos = 0;
        for (int i = 0; i < n; ++i) {
            if (s[i] == 'x') {
                pos = i;
                break;
            }
        }
        if (pos % 2 == 0) {
            long long res = 0;
            for (int i = 0; i <= 9; ++i) {
                if (((sum + i) * 9) % 10 == (s[n - 1] - '0')) {
                    res = i;
                    break;
                }
            }
            cout <<res<<endl;
        }
        else {
            long long res = 0;
            for (int i = 0; i <= 9; ++i) {
                long long p = i * 2;
                long long cur = 0;
                if (p > 9) {
                    cur = 1 + (p % 10);
                }
                else {
                    cur = p;
                }
                if (((sum + cur) * 9) % 10 == (s[i] - '0')) {
                    res = i;
                    break;
                }
            }
            cout <<res<<endl;
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Correct 1 ms 364 KB Output is correct
5 Incorrect 1 ms 364 KB Output isn't correct
6 Incorrect 1 ms 364 KB Output isn't correct
7 Incorrect 1 ms 364 KB Output isn't correct
8 Incorrect 1 ms 364 KB Output isn't correct
9 Incorrect 1 ms 364 KB Output isn't correct
10 Incorrect 1 ms 364 KB Output isn't correct