#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
#define ll int
#define sz(x) (ll)x.size()
#define F first
#define S second
#define endl "\n"
#define pb push_back
typedef vector <ll> vi;
typedef vector <long long> vl;
typedef pair <ll,ll> ii;
typedef vector <ii> vii;
#define dbg(x) cout<<#x<<": "<<x<<endl;
#define dbg2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl;
#define dbg3(x,y,z) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<" "<<#z<<": "<<z<<endl;
void printVct(vl &v){
for(ll i =0; i<sz(v); i++){
cout<<v[i]<<" ";
}
cout<<endl;
}
vector <vl> arr, s;
long long getSum(ll x, ll l, ll r){
if (l > r) return (ll)0;
if (l == 0) return s[x][r];
return s[x][r] - s[x][l-1];
}
#define N 301
#define MAX_Y 9
ll maxY = MAX_Y;
ll n, m;
long long dp[N+1][N+1][2];
long long solve(ll i, ll y, bool specialCase){ //wall already present at position i with height y (y = 0 => 1 block)
if (i >= n) return 0;
if (i == n-2){
long long ans = getSum(n-1, 0, y);
if (!specialCase){
for (ll j = y+1; j<=maxY; j++){
ans = max(ans, getSum(i, y+1, j));
}
}
return ans;
//MEMOIZE HERE TOO!!
}
// if (dp[i] != -1) return dp[i];
long long ans =0;
//i+1
if (i < n-1 && !specialCase){
for (ll j =0; j<=maxY; j++){
if (j <= y){
ans = max(ans, solve(i+1, j, true) + getSum(i+1, j+1, y));
}
else{
ans = max(ans, solve(i+1, j, false) + getSum(i, y+1, j)); //MORE ATTENTION HERE!! problem with i?? (dublicate) => or covered by special case? => yes it is covered
}
}
}
//i+2
if (i < n-2){
for (ll j =0; j<=maxY; j++){
ans = max(ans, solve(i+2, j, false) + getSum(i+1, 0, max(y,j)));
}
}
//i+3
if (i < n-3){
for (ll j =0; j<=maxY; j++){
ans = max(ans, solve(i+3, j, false) + getSum(i+1, 0, y) + getSum(i+2, 0, j));
}
}
return ans;
// dp[i] = ans;
// return dp[i];
}
void init_dp(){
// for (ll i =0; i<=n; i++){
// dp[i] = -1;
// }
}
long long max_weights(int NN, int M, vi X, vi Y, vi w){
n = NN, m = M;
maxY = min(MAX_Y, n);
//create arr
arr.assign(n, vl(n,0));
s.assign(n, vl(n,0));
for (ll i =0; i<m; i++){
ll x = X[i], y = Y[i];
arr[x][y] = w[i];
s[x][y] = w[i];
}
for (ll i = 0; i<n; i++){
for (ll j =1;j<n;j++){
s[i][j] += s[i][j-1];
}
}
// cout<<"arr: ";
// printVct(arr);
// long long ans = 0;
// init_dp();
// ans = solve(0);
// for (ll i = 1; i<=min(2, n-1); i++){
// init_dp();
// ans = max(ans, solve(i) + arr[i-1]);
// }
long long ans = 0;
for (ll j = 0; j<=maxY; j++){
init_dp();
ans = max(ans, solve(0,j,false));
}
for (ll i = 1; i<=min(2, n-1); i++){
for (ll j = 0; j<=maxY; j++){
init_dp();
ans = max(ans, solve(i, j, false));
}
}
return ans;
}
/*
5 4
0 2 5
1 1 2
4 4 1
3 3 3
7 7
0 0 2
1 0 1
2 0 0
3 0 5
4 0 3
5 0 3
6 0 4
6 4
0 2 5
2 1 4
4 4 1
6 3 3
6 6
0 2 5
1 1 4
0 4 1
0 3 3
1 2 4
1 6 2
2 3
0 1 2
0 0 4
1 1 3
5 4
0 2 5
1 1 2
4 4 1
3 3 3
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1139 ms |
1758264 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '2', found: '58721' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1129 ms |
1771120 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1129 ms |
1771120 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1139 ms |
1758264 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |