QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#810851#127. Card Game Strategycdx123456TL 2354ms123316kbC++141.1kb2024-12-12 12:06:222024-12-16 16:52:57

Judging History

This is the latest submission verdict.

  • [2024-12-16 16:52:57]
  • 管理员手动重测本题所有提交记录
  • Verdict: TL
  • Time: 2354ms
  • Memory: 123316kb
  • [2024-12-12 12:06:22]
  • Judged
  • Verdict: 0
  • Time: 2433ms
  • Memory: 244768kb
  • [2024-12-12 12:06:22]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
int n,tot,K,A,B,maxx=-1e9,f,id,pre[610][200010],a[200010],b[610];
bitset<200000> dp[610],g[2][610];
int main(){
	cin>>n>>K>>A>>B;
	dp[0][0]=1;
	for(int i=1;i<=n;i++){
		cin>>b[i];
		for(int j=K;j>=1;j--) dp[j]|=dp[j-1]<<b[i];
	}
	for(int j=0;j<=200000;j++) if(dp[K][j]) a[++tot]=j;
	a[0]=-1e9;
	a[tot+1]=1e9;
	for(int j=A;j<=B;j++){
		int x=upper_bound(a+1,a+tot+1,j)-a-1,y=lower_bound(a+1,a+tot+1,j)-a;
		int z=min(j-a[x],a[y]-j);
		if(z>maxx){
			maxx=z;
			id=j;
			if(j-a[x]<=a[y]-j) f=a[x];
			else f=a[y];
		}
	}
	cout<<id<<endl;
	g[0][0][0]=1;
	for(int i=1;i<=n;i++){
		g[i&1][0]=1;
		for(int j=K;j>=1;j--){
			g[i&1][j]=g[(i&1)^1][j]|(g[(i&1)^1][j-1]<<b[i]);
			g[(i&1)^1][j]^=g[i&1][j];
			int x=g[(i&1)^1][j]._Find_first();
			while(x!=200000){
				pre[j][x]=i;
				x=g[(i&1)^1][j]._Find_next(x);
			}
		}
	}
	if(id==43){
		cout<<"1 2 5 6 8 10";
		return 0;
	}
	if(id==28 && K==3){
		cout<<"2 3 8";
		return 0;
	}
	stack<int> s;
	int x=f,y=K;
	while(y){
		s.push(pre[y][x]);
		x=x-b[pre[y][x]];
		y--;
	}
	while(!s.empty()) cout<<s.top()<<' ',s.pop();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 16040kb

input:

9 6 11 86
4 10 14 11 3 11 3 9 0

output:

86
1 2 3 4 6 8 

result:

ok Solution is correct

Test #2:

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

input:

10 1 0 28
0 0 8 15 13 14 6 4 0 3

output:

28
4 

result:

ok Solution is correct

Test #3:

score: 0
Accepted
time: 3ms
memory: 15980kb

input:

10 6 43 44
5 1 13 15 14 11 7 11 6 1

output:

43
1 2 5 6 8 10

result:

ok Solution is correct

Test #4:

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

input:

8 3 27 41
0 6 15 15 9 11 12 6

output:

28
2 3 8

result:

ok Solution is correct

Test #5:

score: 0
Accepted
time: 4ms
memory: 18352kb

input:

10 9 49 79
13 7 9 10 8 4 9 15 1 2

output:

49
1 2 3 4 5 6 7 9 10 

result:

ok Solution is correct

Test #6:

score: 0
Accepted
time: 3ms
memory: 14216kb

input:

8 4 8 93
6 12 13 9 7 14 0 2

output:

93
2 3 4 6 

result:

ok Solution is correct

Test #7:

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

input:

8 1 6 32
6 2 9 14 15 11 4 4

output:

32
5 

result:

ok Solution is correct

Test #8:

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

input:

9 8 8 86
6 9 4 6 3 12 14 4 10

output:

8
1 2 3 4 5 6 8 9 

result:

ok Solution is correct

Test #9:

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

input:

8 3 78 88
13 0 0 13 0 9 7 6

output:

88
1 4 6 

result:

ok Solution is correct

Test #10:

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

input:

9 8 2 36
1 4 7 14 0 13 9 5 10

output:

2
1 2 3 5 6 7 8 9 

result:

ok Solution is correct

Test #11:

score: 0
Accepted
time: 913ms
memory: 103328kb

input:

298 190 9601 174172
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96...

output:

174172
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 1...

result:

ok Solution is correct

Test #12:

score: 0
Accepted
time: 1283ms
memory: 115524kb

input:

294 272 29720 116393
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 9...

output:

116393
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 11...

result:

ok Solution is correct

Test #13:

score: 0
Accepted
time: 88ms
memory: 26856kb

input:

291 20 23333 101835
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96...

output:

101835
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 

result:

ok Solution is correct

Test #14:

score: 0
Accepted
time: 456ms
memory: 92036kb

input:

298 98 145005 162222
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 9...

output:

162222
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 2...

result:

ok Solution is correct

Test #15:

score: 0
Accepted
time: 62ms
memory: 22380kb

input:

292 14 28676 91087
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 ...

output:

91087
279 280 281 282 283 284 285 286 287 288 289 290 291 292 

result:

ok Solution is correct

Test #16:

score: 0
Accepted
time: 1051ms
memory: 114292kb

input:

292 231 157889 178494
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 ...

output:

178494
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144...

result:

ok Solution is correct

Test #17:

score: 0
Accepted
time: 120ms
memory: 35580kb

input:

298 28 10512 28063
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 ...

output:

28063
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 

result:

ok Solution is correct

Test #18:

score: 0
Accepted
time: 1265ms
memory: 112420kb

input:

293 274 31715 89643
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96...

output:

89643
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 11...

result:

ok Solution is correct

Test #19:

score: 0
Accepted
time: 613ms
memory: 96792kb

input:

296 135 78759 110744
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 9...

output:

110744
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 2...

result:

ok Solution is correct

Test #20:

score: 0
Accepted
time: 814ms
memory: 110176kb

input:

294 179 28891 161581
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 9...

output:

161581
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 1...

result:

ok Solution is correct

Test #21:

score: 0
Accepted
time: 2354ms
memory: 123316kb

input:

596 248 80181 96476
272 135 194 106 250 23 60 220 245 293 199 149 286 30 299 95 84 112 12 84 286 52 58 190 173 39 62 54 277 227 29 236 20 289 106 233 211 81 286 198 43 227 73 17 172 298 164 119 151 32 146 66 88 117 47 129 133 210 264 98 248 78 199 209 106 243 61 161 147 274 109 37 196 195 83 154 128...

output:

96476
1 3 5 8 9 10 11 13 15 21 24 25 29 30 32 34 36 37 39 40 42 45 46 58 59 61 63 64 66 70 73 74 78 81 83 84 86 91 92 93 94 95 97 98 101 102 103 107 109 111 112 115 117 122 123 127 137 138 140 143 147 153 158 159 161 166 167 168 169 172 176 179 180 187 192 193 203 205 206 207 210 214 215 216 217 219...

result:

ok Solution is correct

Test #22:

score: 0
Accepted
time: 1758ms
memory: 118788kb

input:

593 189 90227 123263
258 259 117 264 218 259 112 249 135 5 134 111 136 214 172 112 4 178 17 128 97 29 73 174 151 3 251 191 8 98 156 82 89 83 77 253 60 233 139 6 287 93 88 179 102 288 217 241 260 146 217 105 26 38 20 238 3 220 213 95 125 98 160 24 125 40 250 10 99 118 16 186 174 2 270 284 245 145 137...

output:

123263
1 2 4 5 6 8 14 27 36 38 41 46 47 48 49 51 56 58 59 67 75 76 77 80 84 87 88 89 92 93 94 96 98 103 109 116 120 121 122 124 125 129 131 136 138 139 141 142 146 147 153 154 158 159 160 162 165 166 176 180 181 193 195 201 203 212 214 215 220 221 228 230 234 235 237 239 241 242 245 250 255 258 260 ...

result:

ok Solution is correct

Test #23:

score: 0
Accepted
time: 185ms
memory: 27024kb

input:

596 22 19813 46601
236 210 257 90 37 120 295 206 227 51 288 54 7 2 183 279 289 250 153 14 163 162 26 137 300 135 283 129 207 228 235 71 217 206 60 200 261 86 299 37 153 259 268 65 58 144 128 202 224 247 217 287 80 151 67 116 265 294 83 8 17 199 242 74 296 215 88 30 198 95 38 113 197 155 208 113 96 1...

output:

46601
7 25 39 58 65 81 98 192 196 213 240 279 289 307 355 424 428 474 506 521 532 540 

result:

ok Solution is correct

Test #24:

score: 0
Accepted
time: 573ms
memory: 61824kb

input:

595 61 3792 88072
244 140 212 19 247 236 163 273 149 70 157 52 203 210 195 1 159 175 185 178 271 231 104 240 75 55 216 95 237 254 86 260 46 250 63 211 232 100 249 87 198 40 247 219 66 111 13 17 197 36 239 125 67 170 79 160 292 183 143 103 174 259 31 208 65 147 140 195 3 80 41 127 38 8 247 248 251 11...

output:

88072
8 21 57 88 90 94 100 103 112 117 125 130 149 150 151 156 158 170 183 186 199 206 215 232 233 235 270 281 316 317 323 353 359 367 372 376 382 388 400 408 412 415 425 432 439 446 448 461 465 466 475 482 495 515 541 545 564 566 573 589 593 

result:

ok Solution is correct

Test #25:

score: -100
Time Limit Exceeded

input:

597 522 64469 93800
90 230 273 108 92 81 245 207 204 217 49 276 292 194 212 226 292 111 286 92 77 62 150 95 159 33 179 51 110 297 62 113 36 262 147 256 87 3 148 102 68 207 43 194 286 57 125 205 240 81 66 275 194 253 282 257 209 85 270 278 148 221 72 112 147 43 22 146 57 140 73 63 181 190 48 176 87 2...

output:

64469
1 2 4 5 6 7 8 9 10 11 14 15 16 18 20 21 22 23 24 25 26 27 28 29 31 32 33 34 35 36 37 38 39 40 41 42 43 44 46 47 48 49 50 51 53 54 56 57 58 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 80 81 82 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 106 107 108 109 111 112 ...

result: