Submission #666661

# Submission time Handle Problem Language Result Execution time Memory
666661 2022-11-29T09:08:01 Z Banan Catfish Farm (IOI22_fish) C++17
0 / 100
1000 ms 2097152 KB
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define double long double
#define endl '\n'
#define sz(a) (int)a.size()
#define pb push_back
#define fs first
#define sc second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
ll const INF = LONG_LONG_MAX;


long long max_weights(int n, int m, std::vector<int> x, std::vector<int> y, std::vector<int> w)
{
    vector<vector<ll>> val(n+5, vector<ll>(n+5, 0)), pref(n+5, vector<ll>(n+5, 0));
    for(int i=0;i<m;i++)
    {
        val[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]+val[i][j];
        }
    }
    vector<vector<vector<ll>>> dp(n+5, vector<vector<ll>>(n+5, vector<ll>(2, 0)));
    for(int j=1;j<=n;j++)
    {
        dp[1][j][0]=dp[1][j-1][0]+val[2][j];
        dp[1][j][1]=dp[1][j-1][1]+val[2][j];
    }
    for(int i=2;i<=n;i++)
    {
        dp[i][0][1]=max(dp[i-1][0][0], dp[i-1][0][1]);
        dp[i][0][0]=dp[i][0][1];
        for(int j=1;j<=n;j++)
        {
            dp[i][0][1]=max(dp[i-1][j][0], dp[i-1][j][1]);
            dp[i][0][0]=dp[i][0][1];
            for(int k=1;k<=j;k++)
            {
                dp[i][j][0]=max(dp[i][j][0], dp[i-1][k][0]+pref[i-1][j]-pref[i-1][k]-pref[i][k]+pref[i+1][j]);
            }
            for(int k=n;k>=j;k--)
            {
                dp[i][j][1]=max(dp[i][j][1], dp[i-1][k][1]-pref[i][j]+pref[i+1][j]);
                dp[i][j][1]=max(dp[i][j][1], dp[i-1][k][0]-pref[i][j]+pref[i+1][j]);
            }
            for(int k=0;k<=n;k++)
            {
                ll val=0;
                if(k<=j)
                {
                    val=max(val, dp[i-2][k][0]+pref[i-1][j]-pref[i-1][k]+pref[i+1][j]);
                    val=max(val, dp[i-2][k][1]+pref[i-1][j]-pref[i-1][k]+pref[i+1][j]);
                }
                else
                {
                    val=max(val, dp[i-2][k][0]+pref[i+1][j]);
                    val=max(val, dp[i-2][k][1]+pref[i+1][j]);
                }
                dp[i][j][0]=max(dp[i][j][0], val);
                dp[i][j][1]=max(dp[i][j][1], val);
            }
        }
    }

//    cout<<endl<<endl;
//    for(int i=0;i<=n;i++)
//    {
//        for(int j=0;j<=n;j++)
//        {
//            cout<<dp[i][j][0]<<' ';
//        }
//        cout<<endl;
//    }
//    cout<<endl<<endl;
//    for(int i=0;i<=n;i++)
//    {
//        for(int j=0;j<=n;j++)
//        {
//            cout<<dp[i][j][1]<<' ';
//        }
//        cout<<endl;
//    }
//    cout<<endl<<endl;

    ll ans=0;
    for(int i=0;i<=n;i++)
        ans=max(ans, max(dp[n][i][0], dp[n][i][1]));

    return ans;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 1107 ms 2097152 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Runtime error 801 ms 2097152 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 780 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 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 216 KB Output is correct
8 Incorrect 0 ms 224 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 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 216 KB Output is correct
8 Incorrect 0 ms 224 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 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 216 KB Output is correct
8 Incorrect 0 ms 224 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 780 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1107 ms 2097152 KB Time limit exceeded
2 Halted 0 ms 0 KB -