Submission #1102347

# Submission time Handle Problem Language Result Execution time Memory
1102347 2024-10-18T03:00:17 Z CDuong Weird Numeral System (CCO21_day1problem2) C++17
0 / 25
1 ms 336 KB
/*
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,fma,bmi,bmi2,sse4.2,popcnt,lzcnt")
*/

#include <bits/stdc++.h>
#define taskname ""
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define i64 long long
#define int long long
#define isz(x) (int)x.size()
using namespace std;

void solve() {
    int k, q, d, m;
    cin >> k >> q >> d >> m;

    vector<int> a(d);
    vector<vector<int>> md(k);
    for (auto &val : a) {
        cin >> val;
        md[val < 0 ? val % k + k : val % k].emplace_back(val);
    }

    vector<int> vec;
    map<int, int> mp;
    auto dfs = [&](auto self, int val) -> bool {
        if (mp.count(val)) return false;
        mp[val] = false;
        for (auto coef : a) {
            if (coef == val) {
                vec.emplace_back(coef);
                return true;
            }
            if ((val - coef) % k == 0 and (val - coef) / k != val and self(self, (val - coef) / k)) {
                vec.emplace_back(coef);
                return true;
            }
        }
        return false;
    };

    while (q--) {
        int n;
        cin >> n;
        mp.clear();
        vec.clear();
        if (!dfs(dfs, n)) {
            cout << "IMPOSSIBLE" << "\n";
        }
        else {
            for (auto val : vec) {
                cout << val << " ";
            }
            cout << "\n";
        }
    }
}

signed main() {

#ifndef CDuongg
    if (fopen(taskname".inp", "r"))
        assert(freopen(taskname".inp", "r", stdin)), assert(freopen(taskname".out", "w", stdout));
#else
    freopen("bai3.inp", "r", stdin);
    freopen("bai3.out", "w", stdout);
    auto start = chrono::high_resolution_clock::now();
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1; //cin >> t;
    while(t--) solve();

#ifdef CDuongg
   auto end = chrono::high_resolution_clock::now();
   cout << "\n"; for(int i = 1; i <= 100; ++i) cout << '=';
   cout << "\nExecution time: " << chrono::duration_cast<chrono::milliseconds> (end - start).count() << "[ms]" << endl;
#endif

}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB Expected integer, but "IMPOSSIBLE" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB Expected integer, but "IMPOSSIBLE" found
2 Halted 0 ms 0 KB -