답안 #1070716

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1070716 2024-08-22T17:09:50 Z beaconmc 메기 농장 (IOI22_fish) C++17
0 / 100
1000 ms 241880 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 = 3005;


set<ll> heights[maxn];
vector<ll> realheights[maxn];

map<ll,ll> fish[maxn];
map<ll,ll> weights[maxn];

map<ll,ll> p[maxn];

vector<array<ll,2>>  dp[maxn];

map<ll,ll> pref[maxn][2];
map<ll,ll> pref2[maxn][2];
map<ll,ll> suff[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,M){
        Y[i]++;
        fish[X[i]][Y[i]] = 1;
        weights[X[i]][Y[i]] = W[i];


        heights[X[i]].insert(Y[i]);
        heights[X[i]+1].insert(Y[i]);
        heights[X[i]+2].insert(Y[i]);
    }
    FOR(i,0,maxn) heights[i].insert(0);

    FOR(i,0,maxn){
        p[i][0] = 0;
        ll prev = 0;
        for (auto&j : heights[i]){
            p[i][j] = p[i][prev] + weights[i][j];
            prev = j;
        }
    }
    FOR(i,0,maxn){
        for (auto&k : heights[i]) realheights[i].push_back(k);
    }
    FOR(i,0,maxn){
        dp[i].resize(heights[i].size());
    }

    FOR(i,1,N+1){
        FOR(X,0,dp[i].size()){
            ll j = realheights[i][X];
            FOR(k,0,2){


                if (i<2) continue;
                ll temp = 0;
                ll add = 0;
                if (k==0){



                    if (p[i-1].count(j) && suff[i-1][0].count(realheights[i][X+1])) temp = max(temp, suff[i-1][0][realheights[i][X+1]] - p[i-1][j]);
                    if (p[i-1].count(j) && suff[i-1][1].count(realheights[i][X+1])) temp = max(temp, suff[i-1][1][realheights[i][X+1]] - p[i-1][j]);

                    // FOR(p,j+1,N+1){
                    //     if (fish[i-1][p]) add += weights[i-1][p];
                    //     temp = max(temp, dp[i-1][p][0] + add);
                    //     temp = max(temp, dp[i-1][p][1] + add);
                    // }
                }else{
                    if (pref[i-1][0].count(j)) temp = max(temp, pref[i-1][0][j]);
                    if (p[i-2].count(j) && pref[i-1][1].count(j)) temp = max(temp, pref[i-1][1][j] + p[i-2][j]);

                    // 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][X][k] = temp;
            }
        }
        ll sz = realheights[i].size();

        FOR(k,0,2){
            ll tempadd = 0;
            ll tempadd2 = 0;


            FOR(j,0,sz){
                tempadd += weights[i][realheights[i][j]];
                suff[i][k][realheights[i][j]] = dp[i][j][k]+tempadd;

            }

            FOR(j,0,sz){
                tempadd2 -= weights[i-1][realheights[i][j]];
                pref[i][k][realheights[i][j]] = dp[i][j][k] + tempadd2;
                pref2[i][k][realheights[i][j]] = dp[i][j][k];
            }
            ll prev = 0;
            FOR(j,1,sz){
                pref[i][k][realheights[i][j]] = max(pref[i][k][realheights[i][j]], pref[i][k][prev]);
                pref2[i][k][realheights[i][j]] = max(pref2[i][k][realheights[i][j]], pref2[i][k][prev]);
                prev = realheights[i][j];
            }
            prev = realheights[i][sz-1];
            FORNEG(j,sz-2,-1){
                suff[i][k][realheights[i][j]] = max(suff[i][k][realheights[i][j]], suff[i][k][prev]);

                prev = realheights[i][j];
            }

        }
        // cout << i << endl;
        // cout << suff[2][2][0] << "FUCK" << endl;

    }


    ll ans = 0;

    FOR(i,0,maxn){
        FOR(j,0,dp[i].size()){
            ans = max(dp[i][j][0], ans);
            ans = max(dp[i][j][1], ans);
        }
    }
    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:9:33: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 | #define FOR(i,x,y) for(ll i=x; i<y; i++)
......
   61 |         FOR(X,0,dp[i].size()){
      |             ~~~~~~~~~~~~~~~~     
fish.cpp:61:9: note: in expansion of macro 'FOR'
   61 |         FOR(X,0,dp[i].size()){
      |         ^~~
fish.cpp:68:20: warning: unused variable 'add' [-Wunused-variable]
   68 |                 ll add = 0;
      |                    ^~~
fish.cpp:9:33: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 | #define FOR(i,x,y) for(ll i=x; i<y; i++)
......
  138 |         FOR(j,0,dp[i].size()){
      |             ~~~~~~~~~~~~~~~~     
fish.cpp:138:9: note: in expansion of macro 'FOR'
  138 |         FOR(j,0,dp[i].size()){
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 914 ms 241880 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2648 KB Output is correct
2 Execution timed out 1029 ms 153148 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 7260 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 2 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 2 ms 2648 KB Output is correct
7 Correct 2 ms 2652 KB Output is correct
8 Incorrect 1 ms 2504 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 2 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 2 ms 2648 KB Output is correct
7 Correct 2 ms 2652 KB Output is correct
8 Incorrect 1 ms 2504 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 2 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 2 ms 2648 KB Output is correct
7 Correct 2 ms 2652 KB Output is correct
8 Incorrect 1 ms 2504 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 7260 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 914 ms 241880 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -