QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#338993#8174. Set Construction275307894aML 2ms3976kbC++142.6kb2024-02-26 16:13:402024-02-26 16:13:40

Judging History

你现在查看的是最新测评结果

  • [2024-02-26 16:13:40]
  • 评测
  • 测评结果:ML
  • 用时:2ms
  • 内存:3976kb
  • [2024-02-26 16:13:40]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=2e3+5,M=N*10+5,K=1000+5,mod=998244353,Mod=+-1;const db eps=1e-9;const ll INF=1e18+7;mt19937 rnd(263082);
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
	Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
	Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
	#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
}using namespace Debug;
int n,m,dp[N];
vector<ll> construct(int m){
	if(m==1) return {0};
	for(int i=1;i<=60;i++){
		int x=i,siz=i;
		if(m>=x&&dp[m]==dp[m-x]+siz){
			auto p=construct(m-x);
			ll y=(1ll<<dp[m])-1;
			for(int j=1;j<=siz;j++) p.emplace_back(y>>j-1);
			return p;
		}
	}
	for(int i=1;i<=20;i++){
		int x=(1<<i)-1,siz=i;
		if(m>=x&&dp[m]==dp[m-x]+siz){
			auto p=construct(m-x);
			ll y=(1ll<<dp[m])-1;
			for(int j=0;j<(1<<siz)-1;j++) p.emplace_back(y^j); 
			return p;
		}
	}
	for(int i=2;i<m;i++) if(dp[m]==dp[i]+dp[m-i+1]){
		auto p=construct(i),q=construct(m-i+1);
		for(ll i:p) q.emplace_back((i+1<<dp[m-i+1])-1);
		return q;
	}
	for(int i=1;i<=m;i++) if(m%i==0&&dp[m]==dp[i]+dp[m/i]){
		auto p=construct(i),q=construct(m/i);
		vector<ll> ans;
		for(ll i:p) for(ll j:q) ans.emplace_back(i<<dp[m/i]|j);
		return ans;
	}
	assert(0);
}
void Solve(){
	int i,j;scanf("%d%d",&n,&m);
	vector<ll> p=construct(m);
	for(ll &i:p)if(i&1){
		for(int j=1;j<=n-dp[m];j++) i=i<<1|1;
	}
	for(ll i:p) printf("%lld ",i);printf("\n");
}
const int lim=30*61;
void init(){
	Me(dp,0x3f);dp[1]=0;
	for(int i=0;i<=60;i++){
		int x=i,siz=i;
		for(int h=x;h<=lim;h++) dp[h]=min(dp[h],dp[h-x]+i);
	}
	gdb(dp[2],dp[5]);
	for(int i=0;i<=20;i++){
		int x=(1<<i)-1,siz=i;
		for(int h=x;h<=lim;h++) dp[h]=min(dp[h],dp[h-x]+siz);
	}
	for(int i=1;i<=lim;i++){
		for(int j=1;j<=i;j++) dp[i]=min(dp[i],dp[j]+dp[i-j+1]);
		for(int j=1;i*j<=lim;j++) dp[i*j]=min(dp[i*j],dp[i]+dp[j]);
	}
	for(int i=2;i<=lim;i++){
		int x=dp[i];
		if(x*(x-1)/2>=i) gdb(i,x);
	}
}
int main(){
	int t=1;init();
	scanf("%d",&t);
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3976kb

input:

3
3 5
4 8
60 2

output:

0 3 2 1 7 
0 15 6 11 4 7 2 3 
0 1152921504606846975 

result:

ok AC

Test #2:

score: -100
Memory Limit Exceeded

input:

30
6 2
6 3
6 4
6 5
6 6
6 7
6 8
6 9
6 10
6 11
6 12
6 13
6 14
6 15
6 16
6 17
6 18
6 19
6 20
6 21
7 2
7 3
7 4
7 5
7 6
7 7
7 8
7 9
7 10
7 11

output:


result: