Submission #950822

#TimeUsernameProblemLanguageResultExecution timeMemory
950822sysiaCatfish Farm (IOI22_fish)C++17
52 / 100
794 ms2097152 KiB
//Sylwia Sapkowska #include <bits/stdc++.h> #include "fish.h" #pragma GCC optimize("O3", "unroll-loops") using namespace std; void __print(int x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << "'" << x << "'";} void __print(const char *x) {cerr << '"' << x << '"';} void __print(const string &x) {cerr << '"' << x << '"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifdef LOCAL #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif typedef long long ll; typedef pair<int, int> T; const ll oo = 1e18; void ckmax(ll &a, ll b){ a = max(a, b); } ll max_weights(int n, int m, vector<int>x, vector<int>y, vector<int>w){ vector pref(n+1, vector<ll>(n+1)); for (int i = 0; i<m; i++){ pref[x[i]+1][y[i]+1] = w[i]; } for (int i = 1; i<=n; i++){ for (int j = 1; j<=n; j++){ pref[i][j] += pref[i][j-1]; } } vector dp(n+1, vector<ll>(3, -oo)); //dp[h][malejacy czy rosnacy][czy ita kolumna zostala ogarnieta] dp[0][0] = 0; dp[0][1] = 0; for (int i = 1; i<=n; i++){ vector new_dp(n+1, vector<ll>(3, -oo)); //h = 0 //1) poprzednia miala dodatnie pole for (int h = 1; h <= n; h++){ new_dp[0][2] = max(new_dp[0][2], max(dp[h][1], dp[h][0]) + pref[i][h]); } //2) poprzednia byla zerem new_dp[0][0] = max(dp[0][2], dp[0][0]); //h > 0 //1) poprzednia byla pusta for (int h = 1; h <= n; h++){ new_dp[h][0] = max(dp[0][2], dp[0][0] + pref[i-1][h]); new_dp[h][1] = max(dp[0][2], dp[0][0] + pref[i-1][h]); } //2) poprzednia cos miala miau ll mx = -oo; for (int h = 1; h <= n; h++){ mx = max(mx, dp[h][0] - pref[i-1][h]); ckmax(new_dp[h][0], mx+pref[i-1][h]); ckmax(new_dp[h][1], mx+pref[i-1][h]); } mx = -oo; for (int h = n; h >= 1; h--){ mx = max(mx, dp[h][1] + pref[i][h]); ckmax(new_dp[h][1], mx - pref[i][h]); } debug(i); for (int h = 0; h <= n; h++){ debug(h, new_dp[h]); } swap(dp, new_dp); } debug(dp); ll ans = 0; for (int h = 0; h <= n; h++){ for (int rep = 0; rep < 3; rep++){ ans = max(ans, dp[h][rep]); } } 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...