Submission #314123

# Submission time Handle Problem Language Result Execution time Memory
314123 2020-10-18T14:33:09 Z phathnv Lun (COCI19_lun) C++11
50 / 50
1 ms 384 KB
#include <bits/stdc++.h>

#define mp make_pair
#define X first
#define Y second
#define taskname "LUN"

using namespace std;

typedef long long ll;
typedef pair <int, int> ii;

int n;
string s;

void readInput(){
    cin >> n >> s;
}

bool valid(){
    int sum = 0;
    for(int i = 0; i < n - 1; i++){
        int tmp = s[i] - '0';
        if ((i + n - 1) & 1)
            tmp <<= 1;
        sum += tmp / 10 + tmp % 10;
    }
    return (sum * 9 % 10 == s[n - 1] - '0');
}

void solve(){
    int p = s.find('x');
    for(char ch = '0'; ch <= '9'; ch++){
        s[p] = ch;
        if (valid()){
            cout << ch;
            return;
        }
    }
    assert(0);
}

int main(){
    if (fopen(taskname".inp", "r")){
        freopen(taskname".inp", "r", stdin);
        freopen(taskname".out", "w", stdout);
    }
    readInput();
    solve();
    return 0;
}

Compilation message

lun.cpp: In function 'int main()':
lun.cpp:45:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   45 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
lun.cpp:46:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   46 |         freopen(taskname".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 288 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 376 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct