Submission #580200

#TimeUsernameProblemLanguageResultExecution timeMemory
580200FatihSolakPresent (RMI21_present)C++17
8 / 100
1631 ms4520 KiB
#include <bits/stdc++.h> #define N 20 #define K 20 using namespace std; int cnt[1<<N]; int g[N+K][N+K]; bool exist[N+K]; bool ck(vector<int> a){ for(auto u:a){ exist[u] = 1; } bool ok = 1; for(auto u:a){ for(auto c:a){ ok &= exist[g[u][c]]; } } for(auto u:a){ exist[u] = 0; } return ok; } vector<int> ans; vector<int> get(int mask,int k){ vector<int> unused; for(int i = 0;i<N;i++){ if( !(mask & (1<<i))) unused.push_back(i+1); } for(int mask2 = 0;mask2 < (1<<unused.size());mask2++){ vector<int> now; for(int i = 0;i<N;i++){ if(mask & (1<<i)) now.push_back(i+1); } for(int i = 0;i<unused.size();i++){ if(mask2 & (1<<i)) now.push_back(unused[i]); } sort(now.begin(),now.end()); if(ck(now))k--; if(k == 0) return now; } } void solve(){ int k; cin >> k; k++; for(int mask = 0;mask < (1<<K);mask++){ vector<int> now; for(int i = 0;i<K;i++){ if(mask & (1<<i)) now.push_back(N+i+1); } int mask2 = 0; for(auto u:now){ for(auto c:now){ if(u == c)continue; mask2 |= (1 << (g[u][c] - 1)); } } if(cnt[mask2] >= k){ //cout << "hey" << endl; ans.clear(); //cout << mask2 << " " << k << endl; for(auto u:get(mask2,k)){ ans.push_back(u); } for(auto u:now){ ans.push_back(u); } break; } else k -= cnt[mask2]; } cout << ans.size() << " "; for(auto u:ans){ cout << u << " "; } cout << "\n"; } int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); #ifdef Local freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); #endif for(int i = 0;i<N+K;i++){ for(int j = 0;j<N+K;j++){ g[i][j] = __gcd(i,j); } } for(int mask = 0;mask<(1<<N);mask++){ vector<int> now; for(int i = 0;i<N;i++){ if(mask & (1<<i)) now.push_back(i+1); } if(!ck(now))continue; for(int mask2 = mask;;){ cnt[mask2]++; if(mask2 == 0)break; mask2 = (mask2 - 1) & mask; } } int t = 1; cin >> t; while(t--){ solve(); } #ifdef Local cout << endl << fixed << setprecision(2) << 1000.0*clock()/CLOCKS_PER_SEC << " milliseconds."; #endif }

Compilation message (stderr)

Main.cpp: In function 'std::vector<int> get(int, int)':
Main.cpp:36:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         for(int i = 0;i<unused.size();i++){
      |                       ~^~~~~~~~~~~~~~
Main.cpp:25:17: warning: control reaches end of non-void function [-Wreturn-type]
   25 |     vector<int> unused;
      |                 ^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...