QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#339005#8174. Set Construction275307894aTL 2ms4148kbC++142.9kb2024-02-26 16:25:582024-02-26 16:26:00

Judging History

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

  • [2024-02-26 16:26:00]
  • 评测
  • 测评结果:TL
  • 用时:2ms
  • 内存:4148kb
  • [2024-02-26 16:25:58]
  • 提交

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){//gdb("add",m,x);
			auto p=construct(m-x);
			ll y=(1ll<<dp[m])-1;
			for(int j=1;j<=siz;j++) p.emplace_back((y>>j-1)<<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){//gdb("pow",m,x);
			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]){//gdb("merge",m,i);
		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=2;i<m;i++) if(m%i==0&&dp[m]==dp[i]+dp[m/i]){//gdb("mul",m,i);
		auto p=construct(i),q=construct(m/i);
		vector<ll> ans;
		for(ll x:p) for(ll y:q) ans.emplace_back(x<<dp[m/i]|y);
		return ans;
	}
	assert(0);
}
void Solve(){
	int i,j;scanf("%d%d",&n,&m);
	vector<ll> p=construct(m);
	for(ll &i:p){
		for(int j=1;j<=n-dp[m];j++) i=i<<1|(i&1);
	}
	assert(p.size()==m);
	assert(find(p.begin(),p.end(),0)!=p.end());
	assert(find(p.begin(),p.end(),(1ll<<n)-1)!=p.end());
	for(ll x:p) for(ll y:p){
		if(find(p.begin(),p.end(),x|y)==p.end()) gdb(x,y);
		assert(find(p.begin(),p.end(),x&y)!=p.end());
		assert(find(p.begin(),p.end(),x|y)!=p.end());	
	}
	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';
}

详细

Test #1:

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

input:

3
3 5
4 8
60 2

output:

0 3 2 1 7 
0 15 12 11 8 7 4 3 
0 1152921504606846975 

result:

ok AC

Test #2:

score: 0
Accepted
time: 2ms
memory: 4100kb

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:

0 63 
0 31 63 
0 63 32 31 
0 31 16 15 63 
0 15 31 32 47 63 
0 7 15 16 23 31 63 
0 63 48 47 32 31 16 15 
0 31 24 23 16 15 8 7 63 
0 15 8 7 31 32 47 40 39 63 
0 7 4 3 15 16 23 20 19 31 63 
0 7 15 16 23 31 32 39 47 48 55 63 
0 3 7 8 11 15 16 19 23 24 27 31 63 
0 3 7 8 11 15 31 32 35 39 40 43 47 63 
0 7...

result:

ok AC

Test #3:

score: 0
Accepted
time: 2ms
memory: 4148kb

input:

30
7 12
7 13
7 14
7 15
7 16
7 17
7 18
7 19
7 20
7 21
7 22
7 23
7 24
7 25
7 26
7 27
7 28
8 2
8 3
8 4
8 5
8 6
8 7
8 8
8 9
8 10
8 11
8 12
8 13
8 14

output:

0 15 31 32 47 63 64 79 95 96 111 127 
0 7 15 16 23 31 32 39 47 48 55 63 127 
0 7 15 16 23 31 63 64 71 79 80 87 95 127 
0 15 8 7 31 32 47 40 39 63 96 111 104 103 127 
0 127 112 111 96 95 80 79 64 63 48 47 32 31 16 15 
0 63 56 55 48 47 40 39 32 31 24 23 16 15 8 7 127 
0 31 24 23 16 15 8 7 63 64 95 88 ...

result:

ok AC

Test #4:

score: 0
Accepted
time: 2ms
memory: 4132kb

input:

30
8 15
8 16
8 17
8 18
8 19
8 20
8 21
8 22
8 23
8 24
8 25
8 26
8 27
8 28
8 29
8 30
8 31
8 32
8 33
8 34
8 35
8 36
9 2
9 3
9 4
9 5
9 6
9 7
9 8
9 9

output:

0 31 16 15 63 64 95 80 79 127 192 223 208 207 255 
0 255 224 223 192 191 160 159 128 127 96 95 64 63 32 31 
0 127 112 111 96 95 80 79 64 63 48 47 32 31 16 15 255 
0 63 48 47 32 31 16 15 127 128 191 176 175 160 159 144 143 255 
0 31 24 23 16 15 8 7 63 64 95 88 87 80 79 72 71 127 255 
0 31 16 15 63 64...

result:

ok AC

Test #5:

score: 0
Accepted
time: 2ms
memory: 3888kb

input:

30
9 10
9 11
9 12
9 13
9 14
9 15
9 16
9 17
9 18
9 19
9 20
9 21
9 22
9 23
9 24
9 25
9 26
9 27
9 28
9 29
9 30
9 31
9 32
9 33
9 34
9 35
9 36
9 37
9 38
9 39

output:

0 127 64 63 255 256 383 320 319 511 
0 63 32 31 127 128 191 160 159 255 511 
0 63 127 128 191 255 256 319 383 384 447 511 
0 31 63 64 95 127 128 159 191 192 223 255 511 
0 31 63 64 95 127 255 256 287 319 320 351 383 511 
0 63 32 31 127 128 191 160 159 255 384 447 416 415 511 
0 511 448 447 384 383 3...

result:

ok AC

Test #6:

score: 0
Accepted
time: 0ms
memory: 4088kb

input:

6
9 40
9 41
9 42
9 43
9 44
9 45

output:

0 31 16 15 63 64 95 80 79 127 128 159 144 143 191 192 223 208 207 255 256 287 272 271 319 320 351 336 335 383 384 415 400 399 447 448 479 464 463 511 
0 15 8 7 31 32 47 40 39 63 64 79 72 71 95 96 111 104 103 127 128 143 136 135 159 160 175 168 167 191 192 207 200 199 223 224 239 232 231 255 511 
0 1...

result:

ok AC

Test #7:

score: -100
Time Limit Exceeded

input:

30
60 1801
60 1802
60 1803
60 1804
60 1805
60 1806
60 1807
60 1808
60 1809
60 1810
60 1811
60 1812
60 1813
60 1814
60 1815
60 1816
60 1817
60 1818
60 1819
60 1820
60 1821
60 1822
60 1823
60 1824
60 1825
60 1826
60 1827
60 1828
60 1829
60 1830

output:

0 140737488355327 281474976710655 281474976710656 422212465065983 562949953421311 1125899906842623 1125899906842624 1266637395197951 1407374883553279 1407374883553280 1548112371908607 1688849860263935 2251799813685247 2251799813685248 2392537302040575 2533274790395903 2533274790395904 26740122787512...

result: