Submission #224926

# Submission time Handle Problem Language Result Execution time Memory
224926 2020-04-19T06:15:43 Z kartel Lun (COCI19_lun) C++14
50 / 50
5 ms 384 KB
#include <bits/stdc++.h>
#define in(x) freopen(x,"r",stdin)
#define out(x) freopen(x,"w",stdout)
#define F first
#define S second
#define pb push_back
#define M ll(998244353)
#define inf ll(2e9+7)
#define N ll(200500)
#define sz(x) x.size()
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast")
#define el '\n'
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree <ll, null_type, less_equal <ll>, rb_tree_tag, tree_order_statistics_node_update> os;

char x;
string s, t;
int n, i, j;

int main()
{
//    in("input.txt");
//    out("output.txt");

    ios_base::sync_with_stdio(false);
    iostream::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> s;

    i = 0;
    while (i < n && s[i] != 'x') i++;

    if (i == 0) x = '1';
           else x = '0';

    for (; x <= '9'; x++)
    {
        t = s;
        t[i] = x;

        for (j = n - 2; j >= 0; j -= 2)
        {
            int y = t[j] - '0';
            if (y != 0)
            {
                y *= 2;
                y %= 9;
                if (y == 0) y = 9;
            }
            t[j] = char(y + '0');
        }

//        cerr << t << el;

        int sum = 0;

        for (j = 0; j < n - 1; j++) sum += t[j] - '0';

        if ((sum * 9) % 10 == int(t[n - 1] - '0'))
        {
            cout << x;
            return 0;
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct