답안 #515602

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
515602 2022-01-19T10:29:29 Z kshitij_sodani Present (RMI21_present) C++14
29 / 100
1741 ms 29112 KB
//#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first 
#define b second
#define endl '\n'

llo pre[61][61];
llo dp[1<<22][23];;
llo cal[1<<22];
llo cal2[1<<22];
llo comp[1<<22];
llo vis[1<<22];
llo vis2[1<<22];
llo vis3[44];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	for(llo i=1;i<=60;i++){
		for(llo j=1;j<=60;j++){
			pre[i][j]=__gcd(i,j);
		}
	}
	llo zz=0;
	llo zz2=0;
	llo bb=17;
	//for(llo i=1;i<=bb;i++){
	llo oo=0;
	llo pp=0;
		for(llo j=0;j<(1<<(bb));j++){

			vector<llo> tt;
			llo cur=0;
			llo ec=-1;
			for(llo i=0;i<bb;i++){
				if((1<<i)&j){
					ec=(1<<i);
					tt.pb(i*2+2);
				}
			}
			if(tt.size()){
				cur=cal2[j-ec];
			}
			for(llo k=0;k+1<tt.size();k++){
				cur|=(1<<((pre[tt[k]][tt.back()]/2)-1));
			}
			cal2[j]=cur;
			if((cur|j)==j){
			//	dp[(1<<bb)-j-1][0]=1;
				vis[j]=1;
				//oo++;
			}
//			pp++;

		}
	//	cout<<11<<endl;
		llo val5=0;
		/*for(llo j=0;j<(1<<bb);j++){
			for(llo i=0;i<bb;i++){

			}
		}*/
		for(llo j=0;j<(1<<bb);j++){
			vector<llo> tt;
			llo cur=0;
			llo ec=0;
			for(llo i=0;i<bb;i++){
				if((1<<i)&j){
					ec=(1<<i);
					tt.pb(i*2+1);
				}
			}
			if(tt.size()){
				cur=cal[j-ec];
			}
			for(llo k=0;k+1<tt.size();k++){
				cur|=(1<<(pre[tt[k]][tt.back()]/2));
			}
			if((cur|j)==j){
				llo su=0;
				for(llo i=0;i<bb;i++){
					llo st=1;
					for(auto k:tt){
						if((1<<(pre[k][2*i+2]/2))&j){

						}
						else{
							st=0;
							break;
						}
					}
					if(st==1){
						su+=(1<<i);
					}
				}
				vis2[j]=1;
				comp[j]=su;
				//cout<<j<<":"<<su<<endl;
			}

			cal[j]=cur;
			/*if(j>0){
				nn[j]+=nn[j-1];
			}*/
		}

	llo t;
	cin>>t;
	while(t--){
		llo n;
		cin>>n;

		if(n==0){
			cout<<0<<endl;
			continue;
		}
		n++;
		for(int i=1;i<=2*bb;i++){
			vis3[i]=0;
		}

		for(llo ii=2*bb;ii>=1;ii--){
			vis3[ii]=-1;
			llo ac=0;
			llo bc=0;
			for(llo j=2*bb;j>=ii;j-=2){
				if(vis3[j]==-1){
					ac+=(1<<((j-1)/2));
				}
				else{
					bc+=(1<<((j-1)/2));
				}
			}
			llo ac2=0;
			llo bc2=0;
			for(llo j=2*bb-1;j>=ii;j-=2){
				if(vis3[j]==-1){
					ac2+=(1<<(j/2));
				}
				else{
					bc2+=(1<<(j/2));
				}
			}
			
			llo zz=0;
			for(llo j=0;j<(1<<bb);j++){
				dp[j][0]=0;
	
				if((j&ac)==0){
					if((j|bc)==j){
	
						dp[j][0]=vis[j];
						
					}
				}
				for(llo i=1;i<=bb;i++){
					if((1<<(i-1))&j){
						dp[j][i]=dp[j][i-1]+dp[j-(1<<(i-1))][i-1];
					}
					else{
						dp[j][i]=dp[j][i-1];
					}
				}
			}
			for(llo j=0;j<(1<<bb);j++){
				if(vis2[j]==1){
					if((j&ac2)>0){
						continue;
					}
					if((j|bc2)==j){
						zz+=dp[comp[j]][bb];
						
					}
				}
			}
			/*if(ii==1){
				cout<<zz<<"::"<<endl;
			}*/
			
			if(zz<n){
				n-=zz;
				vis3[ii]=1;
				continue;
			}

		}
		vector<llo> ans;
		for(int i=1;i<=2*bb;i++){
			if(vis3[i]==1){
				ans.pb(i);
			}
		}
		cout<<ans.size()<<" ";
		for(auto j:ans){
			cout<<j<<" ";
		}
		cout<<endl;
	}
	/*cout<<zz<<endl;
	cout<<zz2<<endl;
	llo su=0;
	llo cot=1500000000;
	cot=1e6;
	for(llo i=1;i<=50;i++){
		llo cur=max(i-(i/3)-1,(llo)0);
		su+=(1LL<<cur);
		if(su>=cot){
			cout<<i<<endl;
			break;
		}
	}
*/




 
	return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:47:19: warning: comparison of integer expressions of different signedness: 'llo' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |    for(llo k=0;k+1<tt.size();k++){
      |                ~~~^~~~~~~~~~
Main.cpp:79:19: warning: comparison of integer expressions of different signedness: 'llo' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |    for(llo k=0;k+1<tt.size();k++){
      |                ~~~^~~~~~~~~~
Main.cpp:27:6: warning: unused variable 'zz' [-Wunused-variable]
   27 |  llo zz=0;
      |      ^~
Main.cpp:28:6: warning: unused variable 'zz2' [-Wunused-variable]
   28 |  llo zz2=0;
      |      ^~~
Main.cpp:31:6: warning: unused variable 'oo' [-Wunused-variable]
   31 |  llo oo=0;
      |      ^~
Main.cpp:32:6: warning: unused variable 'pp' [-Wunused-variable]
   32 |  llo pp=0;
      |      ^~
Main.cpp:60:7: warning: unused variable 'val5' [-Wunused-variable]
   60 |   llo val5=0;
      |       ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1668 ms 29108 KB Output is correct
2 Correct 1628 ms 29108 KB Output is correct
3 Correct 1642 ms 29104 KB Output is correct
4 Correct 1656 ms 29112 KB Output is correct
5 Correct 1695 ms 29112 KB Output is correct
6 Correct 1718 ms 29108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1668 ms 29108 KB Output is correct
2 Correct 1628 ms 29108 KB Output is correct
3 Correct 1642 ms 29104 KB Output is correct
4 Correct 1656 ms 29112 KB Output is correct
5 Correct 1695 ms 29112 KB Output is correct
6 Correct 1718 ms 29108 KB Output is correct
7 Correct 1650 ms 29104 KB Output is correct
8 Correct 1741 ms 29108 KB Output is correct
9 Correct 1597 ms 29104 KB Output is correct
10 Correct 1656 ms 29112 KB Output is correct
11 Correct 1616 ms 29108 KB Output is correct
12 Correct 1640 ms 29108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1668 ms 29108 KB Output is correct
2 Correct 1628 ms 29108 KB Output is correct
3 Correct 1642 ms 29104 KB Output is correct
4 Correct 1656 ms 29112 KB Output is correct
5 Correct 1695 ms 29112 KB Output is correct
6 Correct 1718 ms 29108 KB Output is correct
7 Correct 1650 ms 29104 KB Output is correct
8 Correct 1741 ms 29108 KB Output is correct
9 Correct 1597 ms 29104 KB Output is correct
10 Correct 1656 ms 29112 KB Output is correct
11 Correct 1616 ms 29108 KB Output is correct
12 Correct 1640 ms 29108 KB Output is correct
13 Incorrect 1692 ms 29112 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1668 ms 29108 KB Output is correct
2 Correct 1628 ms 29108 KB Output is correct
3 Correct 1642 ms 29104 KB Output is correct
4 Correct 1656 ms 29112 KB Output is correct
5 Correct 1695 ms 29112 KB Output is correct
6 Correct 1718 ms 29108 KB Output is correct
7 Correct 1650 ms 29104 KB Output is correct
8 Correct 1741 ms 29108 KB Output is correct
9 Correct 1597 ms 29104 KB Output is correct
10 Correct 1656 ms 29112 KB Output is correct
11 Correct 1616 ms 29108 KB Output is correct
12 Correct 1640 ms 29108 KB Output is correct
13 Incorrect 1692 ms 29112 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1668 ms 29108 KB Output is correct
2 Correct 1628 ms 29108 KB Output is correct
3 Correct 1642 ms 29104 KB Output is correct
4 Correct 1656 ms 29112 KB Output is correct
5 Correct 1695 ms 29112 KB Output is correct
6 Correct 1718 ms 29108 KB Output is correct
7 Correct 1650 ms 29104 KB Output is correct
8 Correct 1741 ms 29108 KB Output is correct
9 Correct 1597 ms 29104 KB Output is correct
10 Correct 1656 ms 29112 KB Output is correct
11 Correct 1616 ms 29108 KB Output is correct
12 Correct 1640 ms 29108 KB Output is correct
13 Incorrect 1692 ms 29112 KB Output isn't correct
14 Halted 0 ms 0 KB -