Submission #680353

# Submission time Handle Problem Language Result Execution time Memory
680353 2023-01-10T16:18:16 Z whqkrtk04 Catfish Farm (IOI22_fish) C++17
35 / 100
1000 ms 2097152 KB
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plll;
#define fi first
#define se second
const int INF = 1e9+1;
const int P = 1000000007;
const ll LLINF = (ll)1e18+1;
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) { for(auto i : v) os << i << " "; os << "\n"; return os; }
template <typename T1, typename T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& p) { os << p.fi << " " << p.se; return os; }

typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;

typedef struct prefix_sum {
    vvll B;
    ll operator()(int x, int s, int e) {
        if(x < 0 || x >= B.size()) return 0LL;
        ll ee = (e >= B[x].size() ? B[x].back() : B[x][e]);
        ll ss = (s < 0 ? B[x].front() : B[x][s]);
        return ee-ss;
    }
    ll operator()(int x, int e) {
        return this->operator()(x, 0, e);
    }
    prefix_sum(vvll &A) {
        for(auto &i : A) {
            B.push_back({0LL});
            for(auto &j : i) B.back().push_back(B.back().back()+j);
        }
    }
} prefix_sum;

ll max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
    vvll brd(N, vll(N, 0LL));
    for(int i = 0; i < M; i++) brd[X[i]][Y[i]] += W[i];
    prefix_sum pre(brd);

    int MX = N, MY = N+1;    
    vvll down(MX, vll(MY, 0LL)), dp(MX, vll(MY, 0LL));
    for(int j = 0; j < MY; j++) {
        down[0][j] = dp[0][j] = pre(1, j);
        down[1][j] = pre(0, j)+pre(2, j);
        dp[1][j] = max(down[1][j], pre(1, j, N)+pre(2, j));
    }
    for(int i = 2; i < MX; i++) {
        for(int j = 0; j < MY; j++) {
            for(int k = 0; k <= j; k++) {
                down[i][j] = max(down[i][j], down[i-1][k]-pre(i, k)+pre(i-1, k, j)+pre(i+1, j));
                down[i][j] = max(down[i][j], dp[i-2][k]-pre(i-1, k)+pre(i-1, j)+pre(i+1, j));
            }
            for(int k = j+1; k < MY; k++) {
                down[i][j] = max(down[i][j], dp[i-2][k]+pre(i+1, j));
                dp[i][j] = max(dp[i][j], dp[i-1][k]-pre(i, j)+pre(i+1, j));
            }
            dp[i][j] = max(dp[i][j], down[i][j]);
        }
    }
    //cout << " " << down << " " << dp << "\n";
    return *max_element(dp.back().begin(), dp.back().end());
}

Compilation message

fish.cpp: In member function 'll prefix_sum::operator()(int, int, int)':
fish.cpp:26:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |         if(x < 0 || x >= B.size()) return 0LL;
      |                     ~~^~~~~~~~~~~
fish.cpp:27:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |         ll ee = (e >= B[x].size() ? B[x].back() : B[x][e]);
      |                  ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 847 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Runtime error 789 ms 2097152 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 732 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 24 ms 1160 KB Output is correct
10 Correct 169 ms 3756 KB Output is correct
11 Correct 22 ms 1108 KB Output is correct
12 Correct 183 ms 3708 KB Output is correct
13 Correct 4 ms 424 KB Output is correct
14 Correct 169 ms 3692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 24 ms 1160 KB Output is correct
10 Correct 169 ms 3756 KB Output is correct
11 Correct 22 ms 1108 KB Output is correct
12 Correct 183 ms 3708 KB Output is correct
13 Correct 4 ms 424 KB Output is correct
14 Correct 169 ms 3692 KB Output is correct
15 Correct 168 ms 3668 KB Output is correct
16 Correct 4 ms 596 KB Output is correct
17 Correct 182 ms 5520 KB Output is correct
18 Correct 190 ms 5496 KB Output is correct
19 Correct 185 ms 5452 KB Output is correct
20 Correct 180 ms 5488 KB Output is correct
21 Correct 187 ms 5580 KB Output is correct
22 Correct 197 ms 7288 KB Output is correct
23 Correct 170 ms 4024 KB Output is correct
24 Correct 174 ms 4856 KB Output is correct
25 Correct 177 ms 3640 KB Output is correct
26 Correct 170 ms 3924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 24 ms 1160 KB Output is correct
10 Correct 169 ms 3756 KB Output is correct
11 Correct 22 ms 1108 KB Output is correct
12 Correct 183 ms 3708 KB Output is correct
13 Correct 4 ms 424 KB Output is correct
14 Correct 169 ms 3692 KB Output is correct
15 Correct 168 ms 3668 KB Output is correct
16 Correct 4 ms 596 KB Output is correct
17 Correct 182 ms 5520 KB Output is correct
18 Correct 190 ms 5496 KB Output is correct
19 Correct 185 ms 5452 KB Output is correct
20 Correct 180 ms 5488 KB Output is correct
21 Correct 187 ms 5580 KB Output is correct
22 Correct 197 ms 7288 KB Output is correct
23 Correct 170 ms 4024 KB Output is correct
24 Correct 174 ms 4856 KB Output is correct
25 Correct 177 ms 3640 KB Output is correct
26 Correct 170 ms 3924 KB Output is correct
27 Execution timed out 1106 ms 294728 KB Time limit exceeded
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 732 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 847 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -