Submission #1102505

#TimeUsernameProblemLanguageResultExecution timeMemory
1102505vjudge1Weird Numeral System (CCO21_day1problem2)C++17
25 / 25
132 ms25984 KiB
#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 (stderr)

Main.cpp: In function 'int main()':
Main.cpp:50:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |             for(int i=0;i<ans.size();i++) {
      |                         ~^~~~~~~~~~~
Main.cpp:52:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |               if(i < ans.size() - 1) cout << ' ';
      |                  ~~^~~~~~~~~~~~~~~~
Main.cpp:35:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |         freopen(__file_name ".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:36:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |         freopen(__file_name ".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...