# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
580200 | FatihSolak | Present (RMI21_present) | C++17 | 1631 ms | 4520 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |