QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#46363#4658. 移除石子Qingyu✨0 0ms0kbC++202.1kb2022-08-29 09:55:102022-08-29 09:55:13

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-08-29 09:55:13]
  • Judged
  • Verdict: 0
  • Time: 0ms
  • Memory: 0kb
  • [2022-08-29 09:55:10]
  • Submitted

answer


#include<bits/stdc++.h>
#define F(i,a,b) for(int i=a,i##end=b;i<=i##end;++i)
#define UF(i,a,b) for(int i=a,i##end=b;i>=i##end;--i)
#define ll long long
using namespace std;
inline int read(){
	int x=0;
	char ch=getchar();
	while(ch<'0'||ch>'9')ch=getchar();
	while(ch>='0'&&ch<='9'){
		x=x*10+(ch^'0');
		ch=getchar();
	}
	return x;
}
int num_[50],cnt_;
inline void write(int x){
	if(x==0){
		putchar('0');
		return;
	}
	while(x){
		num_[++cnt_]=x%10;
		x/=10;
	}
	while(cnt_)putchar(num_[cnt_--]+'0');
}
int n,k,l[1002],r[1002];
#define mod 1000000007
const int K=3;
struct S{
	int f[3][3];
	inline S upd(int v){
		S nxt;
		F(i,0,2)F(j,0,2)nxt.f[i][j]=k+1;
		F(i,0,2)F(j,0,min(2,K-i)){
			F(d,max(0,i+j-2),i){
				F(u,0,min(2,K-i-j)){
					nxt.f[i+j-d][u]=min(nxt.f[i+j-d][u],f[i][j]+max(i+j+u-v,int(i+j+u==v-1)));
				}
			}
		}
		return nxt;
	}
};
inline bool operator<(const S &x,const S &y){
	return memcmp(x.f,y.f,9<<2)<0;
}
inline int check(){
	if(n>=4)return k==1&&(*max_element(l+1,l+n+1))<=0;
	bool flag1=false,flag2=false;
	F(i,1,n)if(l[i]>1||r[i]<1)return k==1&&(*max_element(l+1,l+n+1))<=0;
	return int(k==1)+(k==1&&(*max_element(l+1,l+n+1))<=0);
}
map<S,int>id;
int cnt,trans[7156][6];
S to[7156];
int dp[1002][7156];
inline void bfs(){
	cnt=0;id.clear();
	S temp;F(i,0,3)F(j,0,3)temp.f[i][j]=k+1;temp.f[0][0]=0;
	id[temp]=++cnt;to[cnt]=temp;
	for(int i=1;i<=cnt;++i){
		F(j,0,5){
			S qwq=to[i].upd(j);
			if(id.count(qwq))trans[i][j]=id[qwq];
			else{
				trans[i][j]=id[qwq]=++cnt;
				to[cnt]=qwq;
			}
		}
	}
}
int main(){
//	freopen("stone.in","r",stdin);
//	freopen("stone.out","w",stdout);
	k=100;bfs();
	F(iakioi,1,read()){
		memset(dp,0,sizeof(dp));
		n=read(),k=read();
		F(i,1,n)l[i]=read(),r[i]=read();
		dp[0][1]=1;
		F(i,0,n-1){
			F(j,1,cnt){
				F(v,max(l[i+1],0),min(r[i+1],4))(dp[i+1][trans[j][v]]+=dp[i][j])%=mod;
				if(r[i+1]>4)dp[i+1][trans[j][5]]=(dp[i+1][trans[j][5]]+1ll*dp[i][j]*min(r[i+1]-l[i+1]+1,r[i+1]-4))%mod;
			}
		}
		ll ans=0;
		F(i,1,cnt)if(to[i].f[0][0]<=k)ans+=dp[n][i];
		ans+=mod-check();
		write(ans%mod);putchar('\n');
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Dangerous Syscalls

input:

10
5 2
1 3
0 5
1 4
0 1
1 2
5 0
0 3
0 1
0 3
0 2
1 1
5 0
1 2
1 3
3 3
3 4
0 0
5 1
1 1
0 4
3 4
0 4
0 4
5 0
1 1
1 5
0 5
0 1
1 4
5 2
3 4
2 4
0 3
1 3
0 1
5 2
1 4
0 4
0 4
1 2
0 1
5 0
0 4
0 5
0 2
3 4
1 1
3 1
0 5
0 4
0 4
3 1
1 5
1 4
1 4

output:


result:


Test #2:

score: 0
Dangerous Syscalls

input:

10
5 0
0 0
1 4
2 4
1 4
0 3
5 0
1 4
1 5
4 5
0 4
3 4
5 0
1 4
0 3
0 2
3 5
1 2
5 1
1 2
0 4
1 3
1 4
2 4
5 0
0 5
0 1
0 1
0 1
1 2
5 0
1 3
0 3
1 2
1 5
2 3
5 1
0 5
1 5
0 4
0 1
0 3
5 0
1 3
1 3
1 5
1 4
1 4
3 1
0 4
0 1
0 5
3 1
1 3
1 5
1 2

output:


result:


Test #3:

score: 0
Dangerous Syscalls

input:

10
5 2
0 5
0 3
0 3
1 4
2 4
5 0
1 3
1 4
0 1
4 4
1 5
5 1
0 3
0 5
1 1
1 2
2 4
5 0
1 5
1 4
1 4
1 3
3 4
5 0
1 2
1 4
3 4
1 3
0 4
5 2
1 3
1 3
0 5
1 5
3 3
5 2
0 5
0 4
1 3
1 4
2 3
5 0
0 3
1 1
1 1
0 2
1 2
3 1
0 4
0 4
0 5
3 1
1 3
1 4
1 3

output:


result:


Test #4:

score: 0
Dangerous Syscalls

input:

10
1000 0
1 1
4 4
5 5
0 0
2 2
1 1
810768785 810768785
4 4
3 3
2 2
3 3
145678201 145678201
539852093 539852093
3 3
824112952 824112952
3 3
929791266 929791266
3 3
3 3
3 3
0 0
2 2
4 4
4 4
3 3
194646042 194646042
2 2
4 4
3 3
922195284 922195284
676532270 676532270
3 3
3 3
3 3
2 2
5 5
0 0
749247771 7492...

output:


result:


Test #5:

score: 0
Dangerous Syscalls

input:

10
1000 0
6 6
1 1
4 4
2 2
560230659 560230659
2 2
213604931 213604931
4 4
324411778 324411778
5 5
5 5
0 0
68050744 68050744
5 5
1 1
363300583 363300583
2 2
2 2
4 4
957157567 957157567
6 6
3 3
1 1
3 3
2 2
4 4
4 4
4 4
6 6
2 2
0 0
5 5
404555679 404555679
3 3
2 2
1 1
6 6
2 2
4 4
6 6
891397980 891397980
...

output:


result:


Test #6:

score: 0
Dangerous Syscalls

input:

10
1000 69
1 1
1 1
4 4
2 2
1 1
4 4
2 2
1 1
4 4
1 1
0 0
0 0
0 0
0 0
2 2
3 3
1 1
2 2
3 3
3 3
0 0
4 4
3 3
1 1
0 0
2 2
80216297 80216297
1 1
2 2
367878274 367878274
174533945 174533945
746703557 746703557
2 2
245782009 245782009
4 4
0 0
3 3
2 2
0 0
4 4
3 3
1 1
3 3
2 2
2 2
0 0
0 0
114241517 114241517
0 0...

output:


result:


Test #7:

score: 0
Dangerous Syscalls

input:

10
1000 65
3 3
3 3
1 1
3 3
1 1
2 2
2 2
2 2
0 0
1 1
0 0
0 0
3 3
4 4
373336720 373336720
1 1
1 1
4 4
1 1
2 2
1 1
2 2
0 0
4 4
1 1
1 1
1 1
0 0
1 1
1 1
0 0
252809300 252809300
707166173 707166173
1 1
960759336 960759336
2 2
2 2
0 0
3 3
0 0
3 3
0 0
4 4
0 0
1 1
2 2
2 2
1 1
1 1
0 0
780478034 780478034
0 0
4...

output:


result:


Test #8:

score: 0
Dangerous Syscalls

input:

10
1000 48
0 0
1 1
2 2
13941343 13941343
2 2
2 2
0 0
265685928 265685928
0 0
1 1
1 1
3060608 3060608
2 2
0 0
0 0
0 0
1 1
15129724 15129724
0 0
4 4
1 1
297040447 297040447
1 1
3 3
0 0
2 2
1 1
4 4
2 2
1 1
0 0
934313429 934313429
1 1
1 1
1 1
0 0
0 0
1 1
686872027 686872027
1 1
1 1
352017933 352017933
0...

output:


result:


Test #9:

score: 0
Dangerous Syscalls

input:

10
1000 0
1 3
0 367881929
0 908183395
0 294640584
0 130052878
0 460518566
0 380428363
1 6
0 617579265
1 855387669
0 2
0 2
0 4
0 730594613
2 275854270
0 1
0 4
0 5
0 151804972
0 567677095
0 479119369
0 665035693
0 3
0 1
0 1
0 3
0 985093649
0 1
0 255818414
0 4
0 1
0 163849171
0 525071507
3 823579180
0 ...

output:


result:


Test #10:

score: 0
Dangerous Syscalls

input:

10
1000 0
0 220657533
0 490453431
0 663241659
0 3
0 5
0 417978574
4 7
0 641068595
0 1
0 4
0 132285008
0 788406229
0 139937681
0 3
0 969737879
3 444383529
1 443896824
0 836047684
2 3
0 3
1 420847062
0 663834045
0 2
0 578231941
0 5
0 1
0 604459134
0 4
0 955346381
0 360957147
4 525140508
0 3
1 15822405...

output:


result:


Test #11:

score: 0
Dangerous Syscalls

input:

10
1000 0
2 678511582
0 154994295
0 5
2 6
0 1
1 2
0 4
0 196232388
0 1
0 3
0 13247534
0 5
7093249 957022507
1 4
0 906064888
1 2
0 5
1 4
0 256766734
0 636905132
0 370094191
0 2
0 117006010
0 4
0 59582976
1 634540188
0 4
0 677905036
0 5
0 400766826
1 5
3 8
0 665083613
0 4
0 5
0 2
0 730308274
0 89231895...

output:


result:


Test #12:

score: 0
Dangerous Syscalls

input:

10
1000 0
0 3
0 5
1 3
0 2
0 377151268
0 4
0 434362897
1 962769308
0 89047812
1 136192105
0 441748730
0 237192940
1 465698860
0 42439355
1 5829347
349949910 802921919
2 5
0 3
1 2
0 390569672
1 607009222
0 512482679
0 416439678
0 3
0 912993280
0 3
3 340960525
0 1
0 688478781
0 5
0 1
1 4
0 712235930
0 ...

output:


result:


Test #13:

score: 0
Dangerous Syscalls

input:

10
1000 0
0 1
0 4
0 4
0 2
0 3
4 8
1 809130801
0 187920166
0 2
0 3
0 254674697
0 649121331
0 197259413
0 192443143
0 917579552
0 49799772
1 302721613
0 723809824
0 4
0 932825140
1 2
1 4
0 1
0 939720825
0 1
0 652682854
0 292912959
0 426026563
0 969801845
1 3
0 3
0 4
882209199 882209204
0 379900439
0 2...

output:


result:


Test #14:

score: 0
Dangerous Syscalls

input:

10
1000 47
0 6
0 7
0 6
1 1
0 8
2 9
1 7
0 8
0 7
3 5
0 7
0 4
0 10
0 6
0 6
0 10
0 7
1 1
0 10
0 1
0 7
1 8
0 10
1 2
0 9
0 7
0 1
1 10
0 3
0 7
0 9
0 2
0 9
0 0
0 9
0 7
0 7
1 2
0 0
1 6
0 9
0 6
0 6
1 2
0 2
0 1
1 6
0 10
1 10
0 9
3 6
0 6
0 7
1 9
0 8
0 10
1 1
1 10
0 0
0 8
0 3
0 6
0 4
0 0
0 9
0 6
0 10
0 9
1 8
0 1...

output:


result:


Test #15:

score: 0
Dangerous Syscalls

input:

10
1000 99
1 10
0 9
0 8
0 10
1 6
0 7
0 9
1 10
0 6
0 7
0 7
0 9
0 8
0 3
0 9
1 4
0 6
0 9
0 9
0 7
0 10
1 8
1 6
0 6
0 8
0 6
0 9
1 1
0 4
0 0
0 0
0 0
0 1
0 6
0 2
1 7
0 9
0 3
0 7
1 6
0 10
0 9
0 10
1 10
0 3
1 9
0 7
0 10
0 7
0 1
0 0
0 10
0 10
1 9
0 7
1 10
0 6
0 2
0 6
0 8
0 6
1 10
0 7
0 6
0 9
0 10
0 5
0 6
1 10...

output:


result:


Test #16:

score: 0
Dangerous Syscalls

input:

10
1000 94
0 27082101
1 2
0 5
0 182284057
0 2
0 854596927
0 486081504
0 1
4 212942070
2 4
0 4
0 5
0 2
0 937988325
0 839634252
259385372 259385374
0 3
1 520768268
0 3
0 609270333
0 838621534
0 384090136
1 3
0 667788367
0 389605576
0 992710428
0 960391094
0 1
2 658423697
1 2
0 273159245
0 4
4 31114796...

output:


result:


Test #17:

score: 0
Dangerous Syscalls

input:

10
1000 99
1 558836520
0 4
0 3
0 534121003
0 5
0 264739171
0 379370191
0 4
0 100490264
0 2
0 3
1 619605387
0 2
0 3
0 5
4 5
1 294486083
1 2
3 990787247
0 1
1 256196937
0 3
0 2
0 166482225
0 5
0 1
0 5
0 109407731
0 4
0 5
0 3
0 180703250
0 3
0 129133161
0 5
2 7
0 264096332
0 1
0 5
0 726281357
0 1762581...

output:


result:


Test #18:

score: 0
Dangerous Syscalls

input:

10
1000 100
0 3
0 1
1 6
740414081 740414084
1 357189447
1 743739464
0 4
0 1
0 5
0 1
0 30073625
0 4
0 2
0 542888320
0 514884644
1 3
1 305222417
0 386325593
0 1
0 3
1 157562404
0 366404826
0 4
0 3
1 619491195
0 5
0 196255155
1 4
1 4
3 8
2 3
1 6
0 5
0 3
0 5
0 1
0 5
0 642145333
0 2
0 181627666
0 2
0 820...

output:


result:


Test #19:

score: 0
Dangerous Syscalls

input:

10
1000 55
0 364881620
0 1
0 851413241
1 4
4 700024576
0 876649436
0 357726767
0 404571776
1 2223463
0 817905335
1 2
0 5
0 4
0 4
0 3
0 847654812
0 3
0 361081695
0 4
0 850218128
0 5
1 4
0 390585804
0 741480334
0 5
0 469714353
0 2
3 7042948
0 427747116
0 2
0 1
0 2
0 2
0 2
0 732348976
0 206547221
0 915...

output:


result:


Test #20:

score: 0
Dangerous Syscalls

input:

10
1000 99
0 4
0 579831503
0 2
1 21069180
0 124983788
0 4
0 356520474
1 211150192
0 4
0 204201013
0 247203842
0 4
1 6
1 3
1 2
3 7
0 3
1 760511272
0 5
4 7
2 5
0 1
1 946697431
0 3
0 689207096
0 1
1 4
1 3
1 3
0 549119893
3 6
1 5
0 2
0 2
1 536582539
1 6
0 282097774
1 6
0 942901239
0 2
0 5
0 777338255
0 ...

output:


result: