Submission #576305

# Submission time Handle Problem Language Result Execution time Memory
576305 2022-06-13T01:59:31 Z eecs Weird Numeral System (CCO21_day1problem2) C++17
25 / 25
1830 ms 2024 KB
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    int K, q, d;
    cin >> K >> q >> d >> *new int;
    vector<int> a(d);
    for (int &x : a) cin >> x;
    unordered_set<ll> f[80];
    while (q--) {
        ll n;
        cin >> n;
        f[0] = {n};
        bool flag = 0;
        for (int i = 1; i < 80; i++) {
            f[i].clear();
            for (ll x : f[i - 1]) {
                for (int y : a) if (!((x - y) % K)) {
                    f[i].insert((x - y) / K);
                }
            }
            if (f[i].count(0)) {
                for (ll x = 0; i; i--) {
                    for (int y : a) if (f[i - 1].count(x * K + y)) {
                        cout << y << " \n"[i == 1];
                        x = x * K + y; break;
                    }
                }
                flag = 1; break;
            }
        }
        if (!flag) cout << "IMPOSSIBLE\n";
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB OK
2 Correct 1 ms 212 KB OK
3 Correct 0 ms 212 KB OK
4 Correct 0 ms 212 KB OK
5 Correct 0 ms 212 KB OK
6 Correct 0 ms 212 KB OK
7 Correct 0 ms 212 KB OK
8 Correct 0 ms 212 KB OK
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB OK
2 Correct 1 ms 212 KB OK
3 Correct 0 ms 212 KB OK
4 Correct 0 ms 212 KB OK
5 Correct 0 ms 212 KB OK
6 Correct 0 ms 212 KB OK
7 Correct 0 ms 212 KB OK
8 Correct 0 ms 212 KB OK
9 Correct 11 ms 1492 KB OK
10 Correct 4 ms 724 KB OK
11 Correct 2 ms 468 KB OK
12 Correct 2 ms 340 KB OK
13 Correct 97 ms 1932 KB OK
14 Correct 30 ms 828 KB OK
15 Correct 10 ms 468 KB OK
16 Correct 0 ms 212 KB OK
17 Correct 1 ms 212 KB OK
18 Correct 1135 ms 2020 KB OK
19 Correct 1830 ms 1964 KB OK
20 Correct 1 ms 212 KB OK
21 Correct 81 ms 1576 KB OK
22 Correct 499 ms 1592 KB OK
23 Correct 728 ms 1600 KB OK
24 Correct 522 ms 1608 KB OK
25 Correct 649 ms 1908 KB OK
26 Correct 767 ms 2024 KB OK
27 Correct 0 ms 212 KB OK
28 Correct 0 ms 212 KB OK