Submission #635449

# Submission time Handle Problem Language Result Execution time Memory
635449 2022-08-26T09:28:57 Z OttoTheDino Catfish Farm (IOI22_fish) C++17
0 / 100
1000 ms 134992 KB
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;

#define rep(i,s,e)              for (ll i = s; i <= e; ++i)
#define rrep(i,s,e)             for (ll i = s; i >= e; --i)
#define len(v)                  (ll)v.size()
#define pb                      push_back
#define all(v)                  v.begin(), v.end()
#define fi                      first
#define se                      second
typedef long long ll;
typedef vector<int> vi;
typedef pair<ll,ll> ii;
typedef pair<ll,ll> pll;

ll max_weights(int n, int m, vi X, vi Y, vi W) {
    bool done[n+5] = {};
    vector<ll> check[n+5], fish[n+5];
    map<ll,ll> w[n+5], dp[n+5][2];

    rep (i,0,m-1) {
        fish[X[i]+1].pb(Y[i]+1);
        w[X[i]+1][Y[i]+1] = W[i];
        check[X[i]+1].pb(Y[i]);
        if (Y[i]==0) done[X[i]+1] = 1;
    }

    rep (i,0,n) {
        if (i) check[i].pb(n);
        if (!done[i]) check[i].pb(0);
    }

    rep (i,1,n) {

        {
            //go bigger
            vector<pll> upd;
            set<ll> st;
            for (ll el : check[i]) upd.pb({el,1});
            for (ll el : fish[i-1]) upd.pb({el,0});
            for (ll el : check[i-1]) upd.pb({el,2});
            sort (all(upd));
            ll sum = 0;
            for (pll el : upd) {
                ll y = el.fi, tp = el.se;
                if (tp==0) {
                    sum += w[i-1][y]; 
                }
                if (tp==1) {
                    ll res;
                    if (len(st)) {
                        res = sum+*st.rbegin();
                    }
                    else res = 0;
                    dp[i][0][y] = max(dp[i][0][y], res);
                }
                if (tp==2) {
                    st.insert(dp[i-1][0][y]-sum);
                }
            }
        }

        {
            //go smaller
            vector<pll> upd;
            ll sum = 0, cur = 0;
            for (ll el : check[i]) upd.pb({el,3});
            for (ll el : fish[i+1]) {
                upd.pb({el, 0});
                sum += w[i+1][el]; 
            }
            for (ll el : fish[i]) {
                upd.pb({el, 1});
                cur += w[i][el];
            }
            for (ll el : check[i-1]) upd.pb ({el, 2});
            sort (all(upd));
            reverse(all(upd));
            set<ll> st;
            for (pll el : upd) {
                ll y = el.fi, tp = el.se;
                if (tp==0) sum -= w[i+1][y]; 
                if (tp==1) cur -= w[i][y];
                if (tp==2) st.insert({dp[i-1][1][y]+cur});
                if (tp==3) {
                    ll res = dp[i-1][0][n];
                    if (len(st)) res = max(res, *st.rbegin());
                    dp[i][1][y] = res;
                    dp[i+1][0][y] = dp[i][1][y];
                }
            }
        }
    }

    ll ans = 0;
    for (ll y : check[n]) {
        ans = max(ans, dp[n][0][y]);
        ans = max(ans, dp[n][1][y]);
    }

    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 318 ms 66196 KB Output is correct
2 Correct 395 ms 76584 KB Output is correct
3 Correct 100 ms 47308 KB Output is correct
4 Correct 116 ms 47344 KB Output is correct
5 Execution timed out 1070 ms 134992 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 738 ms 88752 KB Output is correct
3 Execution timed out 1006 ms 104108 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 99 ms 47308 KB Output is correct
2 Correct 113 ms 47264 KB Output is correct
3 Incorrect 153 ms 49176 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '16089992176629'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 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 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Incorrect 1 ms 468 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '188483049066'
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 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 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Incorrect 1 ms 468 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '188483049066'
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 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 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Incorrect 1 ms 468 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '188483049066'
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 99 ms 47308 KB Output is correct
2 Correct 113 ms 47264 KB Output is correct
3 Incorrect 153 ms 49176 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '16089992176629'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 318 ms 66196 KB Output is correct
2 Correct 395 ms 76584 KB Output is correct
3 Correct 100 ms 47308 KB Output is correct
4 Correct 116 ms 47344 KB Output is correct
5 Execution timed out 1070 ms 134992 KB Time limit exceeded
6 Halted 0 ms 0 KB -