QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#479951#8811. Heat Strokereal_sigma_team#6 421ms258896kbC++201.8kb2024-07-15 22:54:542024-07-15 22:54:54

Judging History

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

  • [2024-07-15 22:54:54]
  • 评测
  • 测评结果:6
  • 用时:421ms
  • 内存:258896kb
  • [2024-07-15 22:54:54]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

void solve();

int main() {
#ifndef LOCAL
	cin.tie(nullptr)->sync_with_stdio(false);
#endif
	cout << fixed << setprecision(30);
	int t = 1;
	// cin >> t;
	while (t--) {
		solve();
	}
}

constexpr int N = 8080;
int c[N], a[N], ans[N][N], dp[N];
vector<int> cnt[N], lft[N], rgt[N];

void solve() {
	int l;
	cin >> l;
	c[0] = N;
	c[l + 1] = N;
	for (int i = 1; i <= l; i++) {
		cin >> c[i];
	}
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		cnt[a[i]].push_back(i);
	}
	for (int i = 0; i <= l; i++) {
		for (int j = 0; j <= l + 1; j++) {
			lft[j].clear();
			rgt[j].clear();
		}
		ans[i][i + 1] = 0;
		for (int k : cnt[i]) {
			if (rgt[i].size() < c[i + 1]) {
				rgt[i].push_back(k);
			} else {
				lft[i].push_back(k);
			}
		}
		for (int j = i + 2; j <= l + 1; j++) {
			ans[i][j] = ans[i][j - 1];
			for (int k : cnt[j - 1]) {
				if (rgt[j - 2].size() + lft[j - 1].size() < c[j - 1]) {
					lft[j - 1].push_back(k);
				} else if (rgt[j - 1].size() < c[j]) {
					rgt[j - 1].push_back(k);
				} else if (!rgt[j - 2].empty() && rgt[j - 2].back() > k) {
					lft[j - 1].push_back(k);
					int nw = rgt[j - 2].back(), nwi = j - 2;
					rgt[j - 2].pop_back();
					while (nwi > i && !rgt[nwi - 1].empty() && rgt[nwi - 1].back() > nw) {
						lft[nwi].push_back(nw);
						nw = rgt[nwi - 1].back();
						rgt[nwi - 1].pop_back();
						nwi--;
					}
					if (nwi != i) {
						ans[i][j]++;
					}
				} else {
					ans[i][j]++;
				}
			}
		}
	}
	dp[0] = 0;
	dp[1] = 0;
	for (int i = 2; i <= l + 1; i++) {
		dp[i] = 0;
		for (int j = i - 1; j >= 0; j--) {
			dp[i] = max(dp[i], dp[j] + ans[j][i]);
		}
	}
	cout << dp[l + 1] << '\n';
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 6
Accepted

Test #1:

score: 6
Accepted
time: 0ms
memory: 3664kb

input:

2
0 0
1
1

output:

1

result:

ok single line: '1'

Test #2:

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

input:

2
0 1
1
1

output:

0

result:

ok single line: '0'

Test #3:

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

input:

2
1 0
1
1

output:

0

result:

ok single line: '0'

Test #4:

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

input:

2
1 1
1
1

output:

0

result:

ok single line: '0'

Test #5:

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

input:

2
2 2
1
1

output:

0

result:

ok single line: '0'

Test #6:

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

input:

2
1 1
2
1 1

output:

0

result:

ok single line: '0'

Test #7:

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

input:

2
2 2
2
1 1

output:

0

result:

ok single line: '0'

Test #8:

score: 0
Accepted
time: 1ms
memory: 5624kb

input:

2
3 3
2
1 1

output:

0

result:

ok single line: '0'

Test #9:

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

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: 0
Accepted
time: 1ms
memory: 3792kb

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: 0
Accepted
time: 1ms
memory: 3756kb

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: 0
Accepted
time: 1ms
memory: 3864kb

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: 0
Accepted
time: 0ms
memory: 3712kb

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
Accepted
time: 0ms
memory: 3672kb

input:

3
0 1 1
2
1 2

output:

0

result:

ok single line: '0'

Test #15:

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

input:

3
1 1 1
3
1 2 2

output:

1

result:

ok single line: '1'

Test #16:

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

input:

3
1 2 0
3
1 1 2

output:

1

result:

ok single line: '1'

Test #17:

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

input:

3
1 2 0
3
1 2 2

output:

1

result:

ok single line: '1'

Test #18:

score: 0
Accepted
time: 1ms
memory: 3616kb

input:

3
1 3 0
4
1 1 1 2

output:

1

result:

ok single line: '1'

Test #19:

score: 0
Accepted
time: 1ms
memory: 5624kb

input:

4
0 2 1 1
4
1 1 2 3

output:

0

result:

ok single line: '0'

Test #20:

score: 0
Accepted
time: 1ms
memory: 3752kb

input:

18
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
33
1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17

output:

15

result:

ok single line: '15'

Test #21:

score: 0
Accepted
time: 284ms
memory: 257056kb

input:

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

output:

843

result:

ok single line: '843'

Test #22:

score: 0
Accepted
time: 421ms
memory: 258896kb

input:

8000
1 0 1 2 3 2 1 1 1 1 2 4 1 3 2 2 0 3 2 0 1 1 1 1 0 0 0 0 1 0 4 4 3 0 0 0 2 1 0 0 0 0 0 0 0 0 0 2 0 3 3 0 2 0 0 0 2 0 0 2 2 0 1 5 3 0 0 3 0 1 1 2 1 1 2 2 0 0 3 0 0 1 0 0 1 0 1 1 2 3 0 0 1 4 1 2 1 1 2 1 0 0 0 2 2 1 1 0 1 1 1 1 1 0 0 0 0 0 1 0 1 0 3 0 1 1 0 1 1 1 0 0 2 1 1 3 3 0 1 0 0 4 1 0 0 1 0 0...

output:

1799

result:

ok single line: '1799'

Test #23:

score: 0
Accepted
time: 297ms
memory: 258204kb

input:

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 1 1 1...

output:

2146

result:

ok single line: '2146'

Test #24:

score: 0
Accepted
time: 255ms
memory: 257644kb

input:

8000
8000 8000 8000 8000 8000 8000 8000 8000 8000 8000 8000 8000 8000 8000 8000 8000 8000 8000 8000 8000 8000 8000 8000 8000 8000 8000 8000 8000 8000 8000 8000 8000 8000 8000 8000 8000 8000 8000 8000 8000 8000 8000 8000 8000 8000 8000 8000 8000 8000 8000 8000 8000 8000 8000 8000 8000 8000 8000 8000 ...

output:

0

result:

ok single line: '0'

Test #25:

score: 0
Accepted
time: 74ms
memory: 117148kb

input:

3579
0 3 5 0 3 0 1 6 5 1 1 7 0 1 2 0 0 4 3 1 0 4 2 8 2 5 2 2 3 2 0 0 1 4 2 2 2 4 2 0 4 1 0 4 0 5 3 4 1 8 6 0 0 0 2 4 1 2 7 8 2 2 3 5 0 1 0 0 2 1 4 6 4 4 1 1 4 2 1 0 3 3 0 4 4 1 1 6 0 1 2 0 0 1 3 7 3 2 1 3 2 2 1 0 0 0 1 5 4 4 3 0 3 4 4 3 2 1 2 2 1 1 2 1 1 3 11 1 2 0 3 0 4 1 3 3 6 2 1 7 6 2 0 1 3 0 1 ...

output:

1634

result:

ok single line: '1634'

Test #26:

score: 0
Accepted
time: 15ms
memory: 47296kb

input:

1357
11 16 5 0 6 10 10 7 5 1 12 13 4 9 4 6 0 6 1 11 2 8 7 8 1 4 8 9 3 3 3 4 1 4 4 1 5 6 18 7 10 6 9 7 10 2 10 6 1 2 4 12 9 5 7 5 4 5 1 4 4 6 1 4 11 3 13 3 12 7 0 3 9 1 5 6 3 2 3 0 13 2 8 1 6 10 4 5 15 1 1 1 2 5 7 8 5 11 3 7 4 2 0 7 3 6 6 0 3 1 5 4 13 13 5 5 0 6 1 7 9 1 8 1 6 8 12 2 2 2 5 8 11 5 7 6 ...

output:

1608

result:

ok single line: '1608'

Test #27:

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

input:

68
38 219 171 204 116 205 90 225 221 43 74 153 142 147 151 133 65 189 196 4 91 93 215 80 213 25 180 16 24 143 60 22 129 190 59 70 242 53 205 95 212 26 69 123 50 47 205 5 62 154 78 203 48 99 118 7 25 151 222 141 151 143 90 90 141 228 193 75
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...

output:

1018

result:

ok single line: '1018'

Test #28:

score: 0
Accepted
time: 1ms
memory: 5880kb

input:

3
137 4887 1630
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...

output:

1483

result:

ok single line: '1483'

Test #29:

score: 0
Accepted
time: 1ms
memory: 3808kb

input:

3
1 7999 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 ...

output:

1

result:

ok single line: '1'

Test #30:

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

input:

4
0 50 50 0
100
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2

output:

0

result:

ok single line: '0'

Test #31:

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

input:

4
0 4000 4000 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...

output:

0

result:

ok single line: '0'

Test #32:

score: 0
Accepted
time: 12ms
memory: 28668kb

input:

800
0 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 0 10 0 11 0 12 0 13 0 14 0 15 0 16 0 17 0 18 0 19 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 2 0 2 1 2 2 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 3 0 3 1 3 2 3 3 3 4 3 5 3 ...

output:

1330

result:

ok single line: '1330'

Subtask #2:

score: 0
Wrong Answer

Test #33:

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

input:

3
1 1 1
3
1 2 1

output:

0

result:

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

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:

100%
Accepted

Dependency #2:

0%