# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1102504 | 2024-10-18T08:08:12 Z | nathan4690 | Weird Numeral System (CCO21_day1problem2) | C++17 | 123 ms | 25968 KB |
#include <bits/stdc++.h> #define ll long long #define ld long double #define el cout << '\n' #define f1(i,n) for(int i=1;i<=n;i++) #define __file_name "" using namespace std; const ll maxn = 1e6+5, inf=1e18; int k,q,d,m,a[maxn]; ll n; vector<ll> mp[maxn], ans; unordered_map<ll, bool> flag; bool check(ll n){ if(flag.find(n) != flag.end()) return false; flag[n] = true; ll v = (n % k + k) % k; for(int item: mp[v]){ if(item == n){ ans.push_back(item); return 1; }else if(check((n - item) / k)){ ans.push_back(item); return 1; } } return 0; } int main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); if(fopen(__file_name ".inp", "r")){ freopen(__file_name ".inp","r",stdin); freopen(__file_name ".out","w",stdout); } // code here cin >> k >> q >> d >> m; f1(i,d) { cin >> a[i]; mp[(a[i] % k + k) % k].push_back(a[i]); } while(q--){ cin >> n; flag.clear(); ans.clear(); if(check(n)){ // reverse(ans.begin(), ans.end()); for(int i=0;i<ans.size();i++) { cout << ans[i]; if(i < ans.size() - 1) cout << ' '; } }else cout << "IMPOSSIBLE"; if(q > 0) cout << "\n"; } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 25168 KB | OK |
2 | Correct | 5 ms | 25168 KB | OK |
3 | Correct | 4 ms | 25168 KB | OK |
4 | Correct | 4 ms | 25168 KB | OK |
5 | Correct | 5 ms | 25168 KB | OK |
6 | Correct | 4 ms | 25336 KB | OK |
7 | Correct | 4 ms | 25168 KB | OK |
8 | Correct | 5 ms | 25336 KB | OK |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 25168 KB | OK |
2 | Correct | 5 ms | 25168 KB | OK |
3 | Correct | 4 ms | 25168 KB | OK |
4 | Correct | 4 ms | 25168 KB | OK |
5 | Correct | 5 ms | 25168 KB | OK |
6 | Correct | 4 ms | 25336 KB | OK |
7 | Correct | 4 ms | 25168 KB | OK |
8 | Correct | 5 ms | 25336 KB | OK |
9 | Correct | 4 ms | 25168 KB | OK |
10 | Correct | 4 ms | 25168 KB | OK |
11 | Correct | 4 ms | 25168 KB | OK |
12 | Correct | 4 ms | 25168 KB | OK |
13 | Correct | 5 ms | 25336 KB | OK |
14 | Correct | 4 ms | 25168 KB | OK |
15 | Correct | 4 ms | 25168 KB | OK |
16 | Correct | 4 ms | 25168 KB | OK |
17 | Correct | 4 ms | 25168 KB | OK |
18 | Correct | 4 ms | 25168 KB | OK |
19 | Correct | 4 ms | 25168 KB | OK |
20 | Correct | 4 ms | 25168 KB | OK |
21 | Correct | 9 ms | 25936 KB | OK |
22 | Correct | 29 ms | 25968 KB | OK |
23 | Correct | 123 ms | 25948 KB | OK |
24 | Correct | 53 ms | 25936 KB | OK |
25 | Correct | 5 ms | 25168 KB | OK |
26 | Correct | 5 ms | 25168 KB | OK |
27 | Correct | 4 ms | 25168 KB | OK |
28 | Correct | 5 ms | 25340 KB | OK |