#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
#define NL '\n'
#define EL cout << NL
#define FOR(i,n) for(int i = 0; i < (n); i++)
#define FORS(i,s,n) for(int i = (s); i < (n); i++)
#define PRINTV(v) for(auto a:v) {cout << a << " ";} EL;
#define PRINTVV(v) for(auto a:v) {PRINTV(a);}
#define f first
#define s second
#define all(v) (v).begin(),(v).end()
#define STRP(p) "{" << (p).f << "," << (p).s << "}"
#define PRINTVP(v) for(auto a:v) {cout << STRP(a) << " ";} EL;
#define PRINTVVP(v) for(auto a:v) {PRINTVP(a);}
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vpl;
typedef vector<vpl> vvpl;
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
std::vector<int> W) {
bool even = true;
bool smallx = true;
bool smally = true;
FOR(i,M) {
if (X[i] % 2 == 1) even = false;
if (X[i] <= 1) smallx = false;
if (Y[i] != 0) smally = false;
}
if (even) {
ll res = 0;
FOR(i,M) {
res += W[i];
}
return res;
}
smallx = true;
if (smallx) {
vl left(N);
vl right(N);
FOR(i,M) {
if (X[i] == 0) left[Y[i]] = W[i];
else right[Y[i]] = W[i];
}
if (N == 2) {
return max(right[0]+right[1],left[0]+left[1]);
}
ll ans = 0;
FOR(i,N) {
ans += right[i];
}
ll psum = ans;
FOR(i,N) {
psum += left[i]-right[i];
ans = max(ans,psum);
}
return ans;
}
if (smally) {
vector<array<array<ll,2>,2>> dp(N);
vl a(N);
FOR(i,M) a[X[i]] = W[i];
dp[0][0] = {0,0};
dp[0][1] = {0,0};
FORS(i,1,N) {
dp[i][0][0] = max(dp[i-1][0][0],dp[i-1][1][0]);
dp[i][1][0] = max(dp[i-1][0][1],dp[i-1][1][1]) + a[i];
dp[i][0][1] = max(dp[i-1][1][0],dp[i-1][0][0] + a[i-1]);
dp[i][1][1] = max(dp[i-1][0][1],dp[i-1][1][1]);
}
return max(dp[N-1][0][0],max(dp[N-1][0][1],max(dp[N-1][1][0],dp[N-1][1][1])));
}
}
Compilation message
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:79:1: warning: control reaches end of non-void function [-Wreturn-type]
79 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
2140 KB |
Output is correct |
2 |
Correct |
22 ms |
2640 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
67 ms |
7248 KB |
Output is correct |
6 |
Correct |
68 ms |
7284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
37 ms |
5420 KB |
Output is correct |
3 |
Correct |
47 ms |
6480 KB |
Output is correct |
4 |
Correct |
19 ms |
2140 KB |
Output is correct |
5 |
Correct |
24 ms |
2636 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
600 KB |
Output is correct |
12 |
Correct |
18 ms |
3676 KB |
Output is correct |
13 |
Correct |
22 ms |
4172 KB |
Output is correct |
14 |
Correct |
19 ms |
3676 KB |
Output is correct |
15 |
Correct |
21 ms |
3932 KB |
Output is correct |
16 |
Correct |
19 ms |
3676 KB |
Output is correct |
17 |
Correct |
21 ms |
3924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
516 KB |
Output is correct |
2 |
Correct |
1 ms |
1884 KB |
Output is correct |
3 |
Incorrect |
13 ms |
2908 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '774766749' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '2268305442' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '2268305442' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '2268305442' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
516 KB |
Output is correct |
2 |
Correct |
1 ms |
1884 KB |
Output is correct |
3 |
Incorrect |
13 ms |
2908 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '774766749' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
2140 KB |
Output is correct |
2 |
Correct |
22 ms |
2640 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
67 ms |
7248 KB |
Output is correct |
6 |
Correct |
68 ms |
7284 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
37 ms |
5420 KB |
Output is correct |
9 |
Correct |
47 ms |
6480 KB |
Output is correct |
10 |
Correct |
19 ms |
2140 KB |
Output is correct |
11 |
Correct |
24 ms |
2636 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
600 KB |
Output is correct |
18 |
Correct |
18 ms |
3676 KB |
Output is correct |
19 |
Correct |
22 ms |
4172 KB |
Output is correct |
20 |
Correct |
19 ms |
3676 KB |
Output is correct |
21 |
Correct |
21 ms |
3932 KB |
Output is correct |
22 |
Correct |
19 ms |
3676 KB |
Output is correct |
23 |
Correct |
21 ms |
3924 KB |
Output is correct |
24 |
Correct |
1 ms |
516 KB |
Output is correct |
25 |
Correct |
1 ms |
1884 KB |
Output is correct |
26 |
Incorrect |
13 ms |
2908 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '774766749' |
27 |
Halted |
0 ms |
0 KB |
- |