답안 #576303

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
576303 2022-06-13T01:52:51 Z eecs Weird Numeral System (CCO21_day1problem2) C++17
25 / 25
1886 ms 2172 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB OK
2 Correct 0 ms 212 KB OK
3 Correct 1 ms 212 KB OK
4 Correct 1 ms 212 KB OK
5 Correct 0 ms 212 KB OK
6 Correct 0 ms 212 KB OK
7 Correct 1 ms 212 KB OK
8 Correct 1 ms 212 KB OK
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB OK
2 Correct 0 ms 212 KB OK
3 Correct 1 ms 212 KB OK
4 Correct 1 ms 212 KB OK
5 Correct 0 ms 212 KB OK
6 Correct 0 ms 212 KB OK
7 Correct 1 ms 212 KB OK
8 Correct 1 ms 212 KB OK
9 Correct 10 ms 1536 KB OK
10 Correct 4 ms 596 KB OK
11 Correct 2 ms 340 KB OK
12 Correct 3 ms 340 KB OK
13 Correct 99 ms 1936 KB OK
14 Correct 32 ms 808 KB OK
15 Correct 11 ms 556 KB OK
16 Correct 0 ms 212 KB OK
17 Correct 1 ms 212 KB OK
18 Correct 1143 ms 2016 KB OK
19 Correct 1886 ms 2172 KB OK
20 Correct 0 ms 212 KB OK
21 Correct 82 ms 1580 KB OK
22 Correct 514 ms 1584 KB OK
23 Correct 749 ms 1612 KB OK
24 Correct 552 ms 1608 KB OK
25 Correct 660 ms 2032 KB OK
26 Correct 778 ms 2072 KB OK
27 Correct 1 ms 212 KB OK
28 Correct 1 ms 212 KB OK