#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> W) {
bool Even = true, Less = true;
for (auto x : X)
{
if (x % 2 != 0)
{
Even = false;
}
if (x > 1)
{
Less = false;
}
}
if (Even)
{
long long sum = 0;
for (auto x : W)
{
sum += x;
}
return sum;
}
if (Less)
{
long long m[N + 3][3];
memset(m, 0, sizeof(m));
for (int i = 0; i < M; i++)
{
m[Y[i]][X[i]] = W[i];
}
for (int i = 1; i < N; i++)
{
m[i][0] += m[i - 1][0];
m[i][1] += m[i - 1][1];
}
long long ans = max(m[N - 1][0], m[N - 1][1]);
if (N == 2)
{
return ans;
}
for (int i = 0; i < N; i++)
{
ans = max(ans, m[i][0] + m[N - 1][1] - m[i][1]);
}
return ans;
}
long long dp[N + 3][3], p[N + 3];
memset(dp, 0, sizeof(dp));
memset(p, 0, sizeof(p));
for (int i = 0; i < M; i++)
{
p[X[i]] = W[i];
}
dp[0][0] = dp[0][1] = 0;
dp[1][0] = p[1];
dp[1][1] = p[0];
for (int i = 2; i < N; i++)
{
dp[i][1] = max({dp[i - 1][0], dp[i - 2][0] + p[i - 1], dp[i - 1][1]});
dp[i][0] = max({dp[i - 1][1] + p[i], dp[i - 1][0]});
}
return max(dp[N - 1][0], dp[N - 1][1]);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
3516 KB |
Output is correct |
2 |
Correct |
31 ms |
4160 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
97 ms |
13292 KB |
Output is correct |
6 |
Correct |
107 ms |
13744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
300 KB |
Output is correct |
2 |
Correct |
49 ms |
8732 KB |
Output is correct |
3 |
Correct |
65 ms |
10460 KB |
Output is correct |
4 |
Correct |
25 ms |
3240 KB |
Output is correct |
5 |
Correct |
33 ms |
4072 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
27 ms |
5404 KB |
Output is correct |
13 |
Correct |
34 ms |
6444 KB |
Output is correct |
14 |
Correct |
28 ms |
5428 KB |
Output is correct |
15 |
Correct |
35 ms |
5996 KB |
Output is correct |
16 |
Correct |
36 ms |
5484 KB |
Output is correct |
17 |
Correct |
30 ms |
5968 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
3412 KB |
Output is correct |
3 |
Correct |
17 ms |
4940 KB |
Output is correct |
4 |
Correct |
13 ms |
4416 KB |
Output is correct |
5 |
Correct |
31 ms |
7016 KB |
Output is correct |
6 |
Correct |
25 ms |
6476 KB |
Output is correct |
7 |
Correct |
31 ms |
7032 KB |
Output is correct |
8 |
Correct |
29 ms |
7044 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
3412 KB |
Output is correct |
3 |
Correct |
17 ms |
4940 KB |
Output is correct |
4 |
Correct |
13 ms |
4416 KB |
Output is correct |
5 |
Correct |
31 ms |
7016 KB |
Output is correct |
6 |
Correct |
25 ms |
6476 KB |
Output is correct |
7 |
Correct |
31 ms |
7032 KB |
Output is correct |
8 |
Correct |
29 ms |
7044 KB |
Output is correct |
9 |
Incorrect |
29 ms |
6476 KB |
1st lines differ - on the 1st token, expected: '99999', found: '66666' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
3516 KB |
Output is correct |
2 |
Correct |
31 ms |
4160 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
97 ms |
13292 KB |
Output is correct |
6 |
Correct |
107 ms |
13744 KB |
Output is correct |
7 |
Correct |
1 ms |
300 KB |
Output is correct |
8 |
Correct |
49 ms |
8732 KB |
Output is correct |
9 |
Correct |
65 ms |
10460 KB |
Output is correct |
10 |
Correct |
25 ms |
3240 KB |
Output is correct |
11 |
Correct |
33 ms |
4072 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
27 ms |
5404 KB |
Output is correct |
19 |
Correct |
34 ms |
6444 KB |
Output is correct |
20 |
Correct |
28 ms |
5428 KB |
Output is correct |
21 |
Correct |
35 ms |
5996 KB |
Output is correct |
22 |
Correct |
36 ms |
5484 KB |
Output is correct |
23 |
Correct |
30 ms |
5968 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
2 ms |
3412 KB |
Output is correct |
26 |
Correct |
17 ms |
4940 KB |
Output is correct |
27 |
Correct |
13 ms |
4416 KB |
Output is correct |
28 |
Correct |
31 ms |
7016 KB |
Output is correct |
29 |
Correct |
25 ms |
6476 KB |
Output is correct |
30 |
Correct |
31 ms |
7032 KB |
Output is correct |
31 |
Correct |
29 ms |
7044 KB |
Output is correct |
32 |
Incorrect |
1 ms |
212 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
33 |
Halted |
0 ms |
0 KB |
- |