Submission #1234645

#TimeUsernameProblemLanguageResultExecution timeMemory
1234645Sir_Ahmed_Imran메기 농장 (IOI22_fish)C++17
0 / 100
438 ms20084 KiB
#include "fish.h" #include <bits/stdc++.h> using namespace std; #define MAXN 1001 #define nl '\n' #define ff first #define ss second #define ll long long #define ld long double #define terminator main #define pll pair<ll,ll> #define add insert #define append push_back #define pii pair<int,int> #define all(x) (x).begin(),(x).end() // 0 decreasing // 1 increasing ll z[MAXN][2]; ll h[MAXN][MAXN]; ll a[MAXN][MAXN]; ll dp[MAXN][MAXN][2]; ll max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w){ for(int i = 0; i < m; i++) a[x[i]][y[i]] = w[i]; for(int i = 0; i < n; i++) for(int j = 1; j < n; j++) a[i][j] += a[i][j - 1]; for(int i = 0; i <= n; i++) for(int j = 0; j < n; j++) for(int k = 0; k < 2; k++) dp[i][j][k] = z[i][k] = -1e18; z[0][0] = z[0][1] = 0; for(int i = 0; i < n; i++){ dp[0][i][0] = 0; dp[0][i][1] = a[1][n - 1]; } ll ans = 0; for(int i = 1; i < n; i++){ z[i][0] = z[i - 1][0]; z[i][1] = max(z[i - 1][0], z[i - 1][1]); for(int j = 0; j < n; j++){ dp[i][j][0] = max(dp[i][j][0], z[i - 1][0] - a[i][j]); dp[i][j][0] = max(dp[i][j][0], z[i - 1][1] + a[i][j] - a[i][j]); dp[i][j][0] = max(dp[i][j][0], dp[i - 1][j][0] + a[i - 1][j] - a[i][j]); dp[i][j][1] = max(dp[i][j][1], z[i - 1][0] + a[i + 1][j]); dp[i][j][1] = max(dp[i][j][1], z[i - 1][1] + a[i][j] + a[i + 1][j]); dp[i][j][1] = max(dp[i][j][1], dp[i - 1][j][1] - a[i][j] + a[i + 1][j]); dp[i][j][1] = max(dp[i][j][1], dp[i - 1][j][0] + a[i - 1][j] + a[i + 1][j]); z[i][0] = max(z[i][0], dp[i - 1][j][1]); z[i][1] = max(z[i][1], dp[i - 1][j][1] - a[i][j]); z[i][1] = max(z[i][1], dp[i - 1][j][0] + a[i - 1][j]); ans = max(ans, max(dp[i - 1][j][1] - a[i][j], dp[i - 1][j][0] + a[i - 1][j])); } for(int j = 1; j < n; j++) dp[i][j][0] = max(dp[i][j][0], dp[i][j - 1][0]); for(int j = n - 1; j >= 0; j--) dp[i][j][1] = max(dp[i][j][1], dp[i][j + 1][1]); } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...