QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#867445#9684. 倾诉lgvc#0 641ms8024kbC++235.2kb2025-01-23 16:29:482025-01-23 16:29:50

Judging History

This is the latest submission verdict.

  • [2025-01-23 16:29:50]
  • Judged
  • Verdict: 0
  • Time: 641ms
  • Memory: 8024kb
  • [2025-01-23 16:29:48]
  • Submitted

answer

#include <bits/stdc++.h>
#define BIT 61
#define SIZ 15
struct bitset {
	long long bits[SIZ];
	void init(void) {for(int i=0;i<SIZ;i++) bits[i]=0;} 
	void set(int x,bool y) {bits[x/BIT]^=((((bits[x/BIT]>>(x%BIT))&1)^y)<<(x%BIT));}
	void setall(bool y) {for(int i=0;i<SIZ;i++) bits[i]=((((long long)y)<<BIT)-(long long)(y));}
	bool q(int x) {return (bits[x/BIT]>>(x%BIT))&1;}
	void operator=(const bitset& y) {for(int i=0;i<SIZ;i++) bits[i]=y.bits[i];}
	void operator|=(const bitset& y) {for(int i=0;i<SIZ;i++) bits[i]|=y.bits[i];}
	void operator&=(const bitset& y) {for(int i=0;i<SIZ;i++) bits[i]&=y.bits[i];}
	void operator^=(const bitset& y) {for(int i=0;i<SIZ;i++) bits[i]^=y.bits[i];}
	void operator+=(const bitset& y) {
		for(int i=0;i<SIZ;i++) {
			bits[i]+=y.bits[i];
			if((bits[i]>>BIT)&1) bits[i]^=(1ll<<BIT),bits[i+1]++;
		}
	}
	void operator-=(const bitset& y) {
		for(int i=0;i<SIZ;i++) {
			bits[i]-=y.bits[i];
			if(bits[i]<0) bits[i]+=(1ll<<BIT),bits[i+1]--;
		}
	}	
	void operator<<=(int k) {
		bitset z;z.init();
		int tmp=k/BIT;
		for(int i=0;i<SIZ-tmp;i++) z.bits[i+tmp]=bits[i];
		k%=BIT;
		z.bits[SIZ-1]<<=k;
		for(int i=SIZ-2;i>=0;i--) {
			long long tmp=z.bits[i];
			z.bits[i]&=((1ll<<(BIT-k))-1);
			z.bits[i+1]|=((tmp^z.bits[i])>>(BIT-k));
			z.bits[i]<<=k;
		}
		for(int i=0;i<SIZ;i++) bits[i]=z.bits[i];
	}
	void operator>>=(int k) {
		bitset z;z.init();
		int tmp=k/BIT;
		for(int i=tmp;i<SIZ;i++) z.bits[i-tmp]=bits[i];
		k%=BIT;
		z.bits[0]>>=k;
		for(int i=1;i<SIZ;i++) {
			z.bits[i-1]|=((z.bits[i]&((1ll<<k)-1))<<(BIT-k));
			z.bits[i]>>=k;
		}
		for(int i=0;i<SIZ;i++) bits[i]=z.bits[i];
	}	
	bitset operator|(const bitset& y) {
		bitset z;
		for(int i=0;i<SIZ;i++) z.bits[i]=bits[i]|y.bits[i];
		return z;
	}
	bitset operator&(const bitset& y) {
		bitset z;
		for(int i=0;i<SIZ;i++) z.bits[i]=bits[i]&y.bits[i];
		return z;
	}
	bitset operator^(const bitset& y) {
		bitset z;
		for(int i=0;i<SIZ;i++) z.bits[i]=bits[i]^y.bits[i];
		return z;
	}	
	bitset operator+(const bitset& y) {
		bitset z;z.bits[0]=0;
		for(int i=0;i<SIZ;i++) {
			z.bits[i]+=bits[i]+y.bits[i];
			if((z.bits[i]>>BIT)&1) z.bits[i]^=(1ll<<BIT),z.bits[i+1]=1;else z.bits[i+1]=0;
		}
		return z;
	}
	bitset operator-(const bitset& y) {
		bitset z;z.bits[0]=0;
		for(int i=0;i<SIZ;i++) {
			z.bits[i]+=bits[i]-y.bits[i];
			if(z.bits[i]<0) z.bits[i]+=(1ll<<BIT),z.bits[i+1]=-1;else z.bits[i+1]=0;
		}
		return z;
	}
	bitset operator<<(int k) {
		bitset z;z.init();
		int tmp=k/BIT;
		for(int i=0;i<SIZ-tmp;i++) z.bits[i+tmp]=bits[i];
		k%=BIT;
		z.bits[SIZ-1]<<=k;
		for(int i=SIZ-2;i>=0;i--) {
			long long tmp=z.bits[i];
			z.bits[i]&=((1ll<<(BIT-k))-1);
			z.bits[i+1]|=((tmp^z.bits[i])>>(BIT-k));
			z.bits[i]<<=k;
		}
		return z;
	}
	bitset operator>>(int k) {
		bitset z;z.init();
		int tmp=k/BIT;
		for(int i=tmp;i<SIZ;i++) z.bits[i-tmp]=bits[i];
		k%=BIT;
		z.bits[0]>>=k;
		for(int i=1;i<SIZ;i++) {
			z.bits[i-1]|=((z.bits[i]&((1ll<<k)-1))<<(BIT-k));
			z.bits[i]>>=k;
		}
		return z;
	}	
	int count(void) {
		int ans=0;
		for(int i=0;i<SIZ;i++) ans+=__builtin_popcountll(bits[i]);
		return ans;
	}
	bool operator<(const bitset& y) {
		for(int i=SIZ-1;i>=0;i--) if(bits[i]^y.bits[i]) return bits[i]<y.bits[i];
		return 0;
	}
	bool operator>(const bitset& y) {
		for(int i=SIZ-1;i>=0;i--) if(bits[i]^y.bits[i]) return bits[i]>y.bits[i];
		return 0;
	}
	bool operator<=(const bitset& y) {
		for(int i=SIZ-1;i>=0;i--) if(bits[i]^y.bits[i]) return bits[i]<y.bits[i];
		return 1;
	}
	bool operator>=(const bitset& y) {
		for(int i=SIZ-1;i>=0;i--) if(bits[i]^y.bits[i]) return bits[i]>y.bits[i];
		return 1;
	}
	bool operator==(const bitset& y) {
		for(int i=SIZ-1;i>=0;i--) if(bits[i]^y.bits[i]) return 0;
		return 1;
	}
}; 
bitset max(bitset& x,bitset& y) {
	for(int i=SIZ-1;i>=0;i--) {
		if(x.bits[i]>y.bits[i]) return x;
		if(x.bits[i]<y.bits[i]) return y;
	}
	return x;
}
bitset min(bitset& x,bitset& y) {
	for(int i=SIZ-1;i>=0;i--) {
		if(x.bits[i]>y.bits[i]) return y;
		if(x.bits[i]<y.bits[i]) return x;
	}
	return x;
}
int T,N,a[20009],K;
bitset f[755],qq[755][755];
int dp[755][755];
bool chk(bitset x) {
	memset(dp[N+1],0x3f,sizeof(dp[N+1]));
	dp[N+1][N+1]=0;
	for(int i=N;i>=1;i--) {
		memset(dp[i],0x3f,sizeof(dp[i]));
		for(int j=N;j>=i;j--) {
			dp[i][j]=std::min(dp[i][j],dp[i][j+1]);
			for(int k=i;k<=j;k++) {
				if(qq[i][k]<=(x<<(j-k))) {
//					printf("%d %d %d %d %d\n",i,k,j,qq[1][1].count(),x.count());
					dp[i][j]=std::min(dp[i][j],dp[k+1][j+1]+(j-k+j-i)*(k-i+1)/2);
				}
			}
		}
	}
	if(dp[1][1]<=K) return 1;
	return 0;
}
signed main(void) {
	scanf("%d",&T);
	while(T--) {
		scanf("%d %d",&N,&K);
		for(int i=1;i<=N;i++) {
			scanf("%d",&a[i]);
			f[i].setall(0);
			f[i].bits[0]=a[i];
			f[i]<<=N;
		}
		for(int i=1;i<=N;i++) {
			qq[i][i]=f[i];
			for(int j=i+1;j<=N;j++) {
				qq[i][j]=(qq[i][j-1]>>1);
				qq[i][j]+=f[j];
			}
		}
		bitset ff;
		for(int i=N+20;i>=0;i--) ff.set(i,1);
		for(int i=N+20;i>=0;i--) {
			ff.set(i,0);
			if(!chk(ff)) {
				ff.set(i,1);
			}
		}
		int st=0;
		for(int i=N+20;i>=0;i--) {
			if(ff.q(i)) {
				st=i;
				break;
			}
		}
		for(int i=st;i>=0;i--) printf("%d",ff.q(i));
		printf("\n");
	}
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 8024kb

input:

5
6 1
11764 28428 28179 18698 6443 20288
6 3
29 17548 61962 31242 8172 4107
6 15
7 2 239427 137145 171239 3
6 4
294 211 407 190 2 2
6 5
197190 265870 12121 144584 21313 14169

output:

110111100001100000000
111100100000101000000
11101001110100001100000
11001011100000
11000000100100011000000

result:

wrong answer 2nd lines differ - expected: '101110011000100110000', found: '111100100000101000000'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Wrong Answer

Test #60:

score: 0
Wrong Answer
time: 122ms
memory: 5976kb

input:

1666
6 1
282 719 29 355 388 275
6 1
348 766 91 299 474 96
6 23
5 2 8554 8554 8554 2
6 1
84 195 23 37 120 117
6 3
8 3 51 62 28 5
6 3
3 64 64 4 4 2
6 9
5 552 552 552 552 5
6 3
3611 1144 417 3461 459 755
6 3
777 315 1007 5 2 1061
6 6
1300 2101 4 1877 360 2434
6 1
384 713 168 25 524 390
6 3
203 18 305 1...

output:

110000100100000
111011010000000
1000010110111000000
1111000100000
11111000000
100000000000
100011001000000
100010001101100000
10000100101000000
100110000010000000
1000001100100000
10011001100000
111001011010000000
1100000110100000
10011011111100000
101011111000000
1011100000000
100101000000000
10111...

result:

wrong answer 6th lines differ - expected: '11110000000', found: '100000000000'

Subtask #6:

score: 0
Time Limit Exceeded

Test #80:

score: 16
Accepted
time: 246ms
memory: 5844kb

input:

3333
6 1000000000
131727 7 4 170194 6 59263
6 1000000000
417714 286613 7 310122 6 4
6 1000000000
63764 2430 2696 6699 8478 22261
6 1000000000
217 131 6 1487 2927 2
6 1000000000
26225 27991 3842 72525 4521 5231
6 1000000000
34409 26001 23563 19345 30764 24919
6 1000000000
97981 138532 59280 82393 128...

output:

10100110001101001000000
10010111011100001100000
101011011110101000000
10110111001100000
110010000010110110000
111100110010110100000
11111011000100010000000
11001111100101100
1100000101001001010100000
100000000000
100111000110001000000
101110110010100111000000
10000000000000000000000
1100000111101000...

result:

ok 3333 lines

Test #81:

score: 16
Accepted
time: 641ms
memory: 5976kb

input:

2000
10 1000000000
4 225227 95031 258432 108444 260818 190505 154686 1 5
10 1000000000
541067 480522 7 372550 533382 366492 200177 240412 6 1
10 1000000000
10004 14230 86468 2812 9690 7106 21976 45928 9749 30567
10 1000000000
12217 2718 4247 9981 12911 1845 2048 4 1387 16384
10 1000000000
46966 1438...

output:

11110100000110100010000000
101001100100010010010000000
1111111110010010000000000
1000000000000000000000000
11010100011000000000
110010110111010010100000000
11000010111011011011000000000
1001001110000111010000000000
11110110001100100100000000
101110111011100111000000000
100001001101001011110000000
10...

result:

ok 2000 lines

Test #82:

score: 0
Time Limit Exceeded

input:

800
25 1000000000
87944 70771 86657 342502 146802 122800 216223 248367 121688 22026 9518 1128 64025 63379 231058 292954 218186 35314 64373 10501 20550 32081 39386 10095 78181
25 1000000000
54665 3 129508 98607 92526 68177 57466 62726 21642 52766 23748 16110 18286 9033 4 6 3 6 2 5 7 5 7 1 4
25 100000...

output:

100110001011001010000000000000000000000000
11001101110010100000000000000
1101110010100110110000000000000000000000
1011101001000100000000000000000000000000
10100110000000000000000000000000
1001111010011010010000000000000000000000
10010000010110010011000000000000000000000000
10000010010000000000000000...

result:


Subtask #7:

score: 0
Skipped

Dependency #4:

0%