답안 #950821

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
950821 2024-03-20T18:19:03 Z sysia 메기 농장 (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;
    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;
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1152 ms 2091420 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Runtime error 989 ms 2097152 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 728 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 420 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 352 KB Output is correct
6 Correct 0 ms 436 KB Output is correct
7 Correct 0 ms 352 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Incorrect 2 ms 344 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '165904432401'
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 420 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 352 KB Output is correct
6 Correct 0 ms 436 KB Output is correct
7 Correct 0 ms 352 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Incorrect 2 ms 344 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '165904432401'
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 420 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 352 KB Output is correct
6 Correct 0 ms 436 KB Output is correct
7 Correct 0 ms 352 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Incorrect 2 ms 344 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '165904432401'
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 728 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1152 ms 2091420 KB Time limit exceeded
2 Halted 0 ms 0 KB -