Submission #950814

# Submission time Handle Problem Language Result Execution time Memory
950814 2024-03-20T18:08:11 Z sysia Catfish Farm (IOI22_fish) C++17
0 / 100
1000 ms 2097152 KB
//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<int>(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;
    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(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]);
        }
        //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 = 1; h <= n; h++){
        for (int rep = 0; rep < 3; rep++){
            ans = max(ans, dp[h][rep]);
        }
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 1106 ms 1926336 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Runtime error 842 ms 2097152 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 712 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '4044', found: '2022'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '4044', found: '2022'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '4044', found: '2022'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 712 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1106 ms 1926336 KB Time limit exceeded
2 Halted 0 ms 0 KB -