Submission #1032823

# Submission time Handle Problem Language Result Execution time Memory
1032823 2024-07-24T09:18:53 Z Mr_Husanboy Catfish Farm (IOI22_fish) C++17
9 / 100
1000 ms 641600 KB
#include "fish.h"
#include <bits/stdc++.h>
 
using namespace std;
 
#define ff first
#define ss second
#define all(a) (a).begin(), (a).end()
#define ll long long
 
template<typename T>
int len(T &a){
    return a.size();
}
 
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

 
long long max_weights(int n, int m, std::vector<int> x, std::vector<int> y,
                      std::vector<int> w) {
    vector<map<int, ll>> s(n);
    vector<map<int, ll>> pref(n);
    for(int i = 0; i < m; i ++) s[x[i]][y[i] + 1] = w[i];
    pref = s;
    for(int i = 0; i < n; i ++){
        s[i][0] = 0;
        if(i) for(auto [a, b] : s[i - 1]) s[i][a] = max(s[i][a], 0ll);
        if(i + 1 < n) for(auto [a, b] : s[i + 1]) s[i][a] = max(s[i][a], 0ll);
        ll cur = 0;
        for(auto &[_, ss] : pref[i]){
            cur += ss;
            ss = cur;
        }
    }
    map<tuple<int,int,int>, ll> memo;

    auto calc = [&](auto &calc, int st, int i, int j)->ll{
        if(st == 1){
            if(i < j){
                return pref[st - 1][j] - pref[st - 1][i];
            }
            return pref[st][i] - pref[st][j];
        }

        if(memo.count({st, i, j})) return memo[{st, i, j}];
        if(i >= j){
            ll mx = 0;
            for(auto [k, val] : s[st - 2]){
                mx = max(mx, calc(calc, st - 1, k, i));
            }
            return memo[{st, i, j}] = mx + pref[st][i] - pref[st][j];
        }
        ll res = 0;
        ll sum = pref[st - 1][j] - pref[st - 1][i];
        for(auto [k, val] : s[st - 2]){
            if(k <= i){
                res = max(res, calc(calc, st - 1, k, i) + sum);
            }else if(k < j){
                res = max(res, calc(calc, st - 1, k, i) + pref[st - 1][j] - pref[st - 1][k]);
            }else res = max(res, calc(calc, st - 1, k, i));
        }
        return memo[{st, i, j}] = res;
    };
    ll ans = 0;
    for(auto [i, _] : s[n - 2]){
        for(auto [j, __] : s[n - 1]){
            ans = max(ans, calc(calc, n - 1, i, j));
        }
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 1062 ms 301648 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Execution timed out 1107 ms 290896 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 246 ms 76884 KB Output is correct
2 Correct 54 ms 45588 KB Output is correct
3 Correct 152 ms 70740 KB Output is correct
4 Correct 199 ms 78428 KB Output is correct
5 Correct 260 ms 81100 KB Output is correct
6 Correct 250 ms 80208 KB Output is correct
7 Correct 267 ms 80820 KB Output is correct
8 Correct 293 ms 81232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 32 ms 2364 KB Output is correct
11 Incorrect 15 ms 1372 KB 1st lines differ - on the 1st token, expected: '278622587073', found: '284499971571'
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 32 ms 2364 KB Output is correct
11 Incorrect 15 ms 1372 KB 1st lines differ - on the 1st token, expected: '278622587073', found: '284499971571'
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 32 ms 2364 KB Output is correct
11 Incorrect 15 ms 1372 KB 1st lines differ - on the 1st token, expected: '278622587073', found: '284499971571'
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 246 ms 76884 KB Output is correct
2 Correct 54 ms 45588 KB Output is correct
3 Correct 152 ms 70740 KB Output is correct
4 Correct 199 ms 78428 KB Output is correct
5 Correct 260 ms 81100 KB Output is correct
6 Correct 250 ms 80208 KB Output is correct
7 Correct 267 ms 80820 KB Output is correct
8 Correct 293 ms 81232 KB Output is correct
9 Execution timed out 1077 ms 641600 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1062 ms 301648 KB Time limit exceeded
2 Halted 0 ms 0 KB -