QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#866793#8811. Heat Strokelgvc0 62ms817248kbC++232.3kb2025-01-22 18:52:162025-01-22 18:52:17

Judging History

This is the latest submission verdict.

  • [2025-01-22 18:52:17]
  • Judged
  • Verdict: 0
  • Time: 62ms
  • Memory: 817248kb
  • [2025-01-22 18:52:16]
  • Submitted

answer

#include <bits/stdc++.h>
//0 qian j ge
//1 hou j ge
#define INF 0x3f3f3f3f
int N,L,va[8009],c[8009],la[8009][8009],vc[100000009][2],su[8009];
std::vector<int> t[8009];
int sv(int n,int x,int y,int op) {
	int id=x*(c[n]+1)+y+su[n-1];
	if(n==N-1) {
		if(x<c[n]&&(x-y)<va[n+1]) return INF;
		return x;
	}
	if(vc[id][op]!=-1) {
		return vc[id][op];
	}
	int ans=INF;
	for(int xx=0;xx<=c[n+1];xx++) {
		int l1=0,l2=0;
		if(xx<c[n+1]) l2=t[n+1][xx+1]-1;else l2=L;
		if(x<c[n]) l1=t[n][x+1]-1;else l1=L;
		int lim=std::min(l1,l2);
		int tp1=la[lim][n],tp2=la[lim][n+1];
		int vv=va[n+1];
		if(op==1) vv-=std::min(x-y,tp1);
		else vv-=(std::max(std::min(x,tp1),y)-y);	
		if(vv<=0) {
			ans=std::min(ans,sv(n+1,xx,0,0)+x);
			ans=std::min(ans,sv(n+1,xx,1,0)+x);
		} else if(xx==c[n+1]&&x==c[n]) {
			ans=std::min(ans,sv(n+1,xx,0,0)+x);
			ans=std::min(ans,sv(n+1,xx,1,0)+x);
//			for(int yy=0;yy<=xx;yy++) {
//				int vt=vv-std::min(yy,tp2);
//			//	if(vt>=0) {
//					ans=std::min(ans,sv(n+1,xx,yy,0)+x);				
			//	}
//			}
		} else {
			int yy=vv;
			if(yy<=tp2) ans=std::min(ans,sv(n+1,xx,yy,0)+x);	
			yy=vv+xx-std::min(xx,tp2);
			ans=std::min(ans,sv(n+1,xx,yy,1)+x);				
		}
//		for(int yy=0;yy<=xx;yy++) {		
//			int vt=vv-std::max(std::min(xx,tp2),xx-yy)+(xx-yy);
//			if(((xx==c[n+1]&&x==c[n])||(vt==0))) {
//				ans=std::min(ans,sv(n+1,xx,yy,1)+x);				
//			}
	//	}
	}
	return vc[id][op]=ans;
}
signed main(void) {
	memset(vc,-1,sizeof(vc));
	scanf("%d",&N);
	for(int i=1;i<=N;i++) {
		scanf("%d",&va[i]);
		t[i].push_back(0);
	}
	scanf("%d",&L);
	for(int i=1;i<=L;i++) {
		int x;
		scanf("%d",&x);
		t[x].push_back(i);
		c[x]++;
		for(int j=1;j<=N;j++) {
			la[i][j]=la[i-1][j];
		}
		la[i][x]=t[x].size()-1;
	}
	for(int i=1;i<=N;i++) {
		su[i]=su[i-1]+(c[i]+1)*(c[i]+1);
		assert(su[i]<=100000000);
	}
	int ll=-1;
	for(int i=1;i<N;i++) {
		for(int x=0;x<=c[i];x++) {
			for(int y=0;y<=x;y++) {
				int qq=su[i-1]+x*(c[i]+1)+y;
				assert(ll<qq);
				ll=qq;
			}
		}
	}
	assert(su[N]<=100000000);
	int ans=0x3f3f3f3f;
	for(int i=0;i<=c[1];i++) {
		for(int j=0;j<=i&&j<=va[1];j++) {
			if((i==c[1])||(j==va[1])) ans=std::min(ans,sv(1,i,j,0));
			if((i==c[1])||(j==va[1])) ans=std::min(ans,sv(1,i,j,1));
		}
	}
//	printf("%d\n",sv(4,0,0,0));
	printf("%d",L-ans);
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 6
Accepted
time: 29ms
memory: 785140kb

input:

2
0 0
1
1

output:

1

result:

ok single line: '1'

Test #2:

score: 6
Accepted
time: 33ms
memory: 785084kb

input:

2
0 1
1
1

output:

0

result:

ok single line: '0'

Test #3:

score: 6
Accepted
time: 24ms
memory: 785092kb

input:

2
1 0
1
1

output:

0

result:

ok single line: '0'

Test #4:

score: 6
Accepted
time: 33ms
memory: 785220kb

input:

2
1 1
1
1

output:

0

result:

ok single line: '0'

Test #5:

score: 6
Accepted
time: 26ms
memory: 785140kb

input:

2
2 2
1
1

output:

0

result:

ok single line: '0'

Test #6:

score: 6
Accepted
time: 35ms
memory: 785228kb

input:

2
1 1
2
1 1

output:

0

result:

ok single line: '0'

Test #7:

score: 6
Accepted
time: 31ms
memory: 784848kb

input:

2
2 2
2
1 1

output:

0

result:

ok single line: '0'

Test #8:

score: 6
Accepted
time: 27ms
memory: 785120kb

input:

2
3 3
2
1 1

output:

0

result:

ok single line: '0'

Test #9:

score: 6
Accepted
time: 27ms
memory: 787652kb

input:

2
298 299
600
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:

3

result:

ok single line: '3'

Test #10:

score: 6
Accepted
time: 28ms
memory: 799228kb

input:

2
1749 1749
3500
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

2

result:

ok single line: '2'

Test #11:

score: 6
Accepted
time: 62ms
memory: 817160kb

input:

2
3999 3999
8000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

2

result:

ok single line: '2'

Test #12:

score: 6
Accepted
time: 51ms
memory: 817248kb

input:

2
1 1
8000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

7998

result:

ok single line: '7998'

Test #13:

score: 6
Accepted
time: 40ms
memory: 817192kb

input:

2
0 0
8000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

8000

result:

ok single line: '8000'

Test #14:

score: 0
Wrong Answer
time: 33ms
memory: 785196kb

input:

3
0 1 1
2
1 2

output:

1

result:

wrong answer 1st lines differ - expected: '0', found: '1'

Subtask #2:

score: 0
Wrong Answer

Test #33:

score: 7
Accepted
time: 31ms
memory: 785152kb

input:

3
1 1 1
3
1 2 1

output:

1

result:

ok single line: '1'

Test #34:

score: 7
Accepted
time: 24ms
memory: 784996kb

input:

3
1 1 1
3
2 1 2

output:

1

result:

ok single line: '1'

Test #35:

score: 0
Wrong Answer
time: 27ms
memory: 785060kb

input:

7
1 1 1 1 1 1 1
8
2 1 6 5 4 3 2 6

output:

5

result:

wrong answer 1st lines differ - expected: '3', found: '5'

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Skipped

Dependency #5:

0%

Subtask #7:

score: 0
Skipped

Dependency #6:

0%

Subtask #8:

score: 0
Skipped

Dependency #1:

0%