Submission #1070477

# Submission time Handle Problem Language Result Execution time Memory
1070477 2024-08-22T14:35:51 Z beaconmc Catfish Farm (IOI22_fish) C++17
0 / 100
1000 ms 9252 KB
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include "fish.h"

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define FOR(i,x,y) for(ll i=x; i<y; i++)
#define FORNEG(i,x,y) for(ll i=x; i>y; i--)

const ll maxn = 305;


bool fish[maxn][maxn];
ll weights[maxn][maxn];



ll dp[maxn][maxn][2];

ll pref[maxn][maxn][2];
ll suff[maxn][maxn][2];


long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
                      std::vector<int> W) {
    FOR(i,0,maxn){
        FOR(j,0,maxn){
                fish[i][j] = false;
                dp[i][j][0] = 0;
                dp[i][j][1] = 0;
        }
    }

    FOR(i,0,M){
        Y[i]++;
        fish[X[i]][Y[i]] = true;
        weights[X[i]][Y[i]] = W[i];
    }

    FOR(i,0,N+1){
        ll tempadd = 0;
        FOR(j,0,N+1){
            // if (fish[i][j]) tempadd += weights[i][j];

            FOR(k,0,2){


                if (i<2) continue;
                ll temp = 0;
                ll add = 0;
                if (k==0){
                    FOR(p,j+1,N+1){
                        if (fish[i-1][p]) add += weights[i-1][p];
                        temp = max(temp, dp[i-1][p][0]);
                        temp = max(temp, dp[i-1][p][1] + add);
                    }
                }else{
                    FOR(p,0,j+1) if (fish[i-2][p]) add += weights[i-2][p];
                    FOR(p,0,j+1){
                        if (fish[i-2][p]) add -= weights[i-2][p];
                        temp = max(temp, dp[i-1][p][0]);
                        temp = max(temp, dp[i-1][p][1] + add);
                    }
                }
                dp[i][j][k] = temp;
            }
        }
    }


    ll ans = 0;
    FOR(i,0,N+1) FOR(j,0,N+1)FOR(k,0,2){
        //if (dp[i][j][k]==305) cout << i << " " << j << " " << k << endl;
        ans = max(ans, dp[i][j][k]);
    }
    return ans;







}

Compilation message

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:43:12: warning: unused variable 'tempadd' [-Wunused-variable]
   43 |         ll tempadd = 0;
      |            ^~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 1047 ms 5948 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1880 KB Output is correct
2 Execution timed out 1059 ms 9252 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1078 ms 1884 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1884 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Correct 1 ms 1884 KB Output is correct
4 Correct 1 ms 1948 KB Output is correct
5 Correct 1 ms 1884 KB Output is correct
6 Correct 1 ms 1972 KB Output is correct
7 Correct 1 ms 1880 KB Output is correct
8 Incorrect 1 ms 1884 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 1 ms 1884 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Correct 1 ms 1884 KB Output is correct
4 Correct 1 ms 1948 KB Output is correct
5 Correct 1 ms 1884 KB Output is correct
6 Correct 1 ms 1972 KB Output is correct
7 Correct 1 ms 1880 KB Output is correct
8 Incorrect 1 ms 1884 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 1 ms 1884 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Correct 1 ms 1884 KB Output is correct
4 Correct 1 ms 1948 KB Output is correct
5 Correct 1 ms 1884 KB Output is correct
6 Correct 1 ms 1972 KB Output is correct
7 Correct 1 ms 1880 KB Output is correct
8 Incorrect 1 ms 1884 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 Execution timed out 1078 ms 1884 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1047 ms 5948 KB Time limit exceeded
2 Halted 0 ms 0 KB -