답안 #1055780

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1055780 2024-08-13T05:16:29 Z vjudge1 메기 농장 (IOI22_fish) C++17
12 / 100
426 ms 123088 KB
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#pragma GCC optimize(2)
vector<int>fishies[100010];
map<int,ll>fishiess[100010];
unordered_map<int,ll>dp[100010][2];
int N;
inline ll ones(int col,int len){
    return (--fishiess[col].upper_bound(len))->second;
}
struct segtree{
    map<int,ll>mp;
    void reset(){
        mp.clear();
        mp[-1]=-1e18;
    }
    segtree(){reset();}
    ll query(int pos){
        return (--mp.upper_bound(pos))->second;
    }
    void upd(int p,ll x){
        if(x>(--mp.end())->second)
            mp[p]=x;
    }
};
struct a_data_type{
    segtree Sec,First,Overal,Third;
    inline ll sec(int pos){
        return Sec.query(N-pos);
    }
    inline ll first(int pos){
        return First.query(pos);
    }
    inline ll overal(int pos){
        return Overal.query(N-pos);
    }
    inline ll third(int pos){
        return Third.query(pos);
    }
    void init(int i) {
        Overal.reset(),
        First.reset(),
        Sec.reset(),
        Third.reset();
        for(auto j:fishies[i]){
            j--;
            ll A=dp[i][0][j];
            ll B=dp[i][1][j];
            Overal.upd(N-j,max(A,B));
            First.upd(j,max(A,B)-ones(i+1,j));
            Sec.upd(N-j,A);
            Third.upd(j,B-ones(i,j)-ones(i+1,j));
        }
    }
} likehell[2];
ll max_weights(int N_,int M,vector<int> X,vector<int> Y,vector<int> W) {
    N=N_;
    for(int i=0;i<M;i++)
        fishies[X[i]+1].push_back(Y[i]+1),
        fishiess[X[i]+1][Y[i]+1]=W[i];
    for(int i=1;i<=N;i++){
        fishiess[i][N+1];
        fishiess[i][0];
        auto it=++fishiess[i].begin();
        while(it!=fishiess[i].end())
            it->second+=prev(it)->second,it++;
    }
    for(int i=1;i<=N;i++)
        fishies[i].push_back(1),
        fishies[i].push_back(N+1);
    for(int i=1;i<=N;i++)
        sort(fishies[i].begin(),fishies[i].end());
    fishiess[N+1][0];
    for(auto i:fishies[1])
        dp[1][1][i-1]=ones(2,i-1);
    int b=0;
    likehell[b].init(1);
    for(int i=2;i<=N;i++){
        for(auto rw:fishies[i]) {
            ll cons=ones(i+1,rw-1)+ones(i-1,rw-1);
            ll F=likehell[!b].first(rw-1);
            ll S=likehell[!b].overal(rw)-ones(i-1,rw-1);
            dp[i][1][rw-1]=cons+max(F,S);
        }
        for(auto rw2:fishies[i]){
            ll cons=ones(i+1,rw2-1)+ones(i-1,rw2-1);
            ll F=likehell[b].third(rw2-1);
            ll S=likehell[b].overal(rw2);
            dp[i][1][rw2-1]=max(dp[i][1][rw2-1],F+cons);
            dp[i][0][rw2-1]=S-ones(i,rw2-1)-ones(i-1,rw2-1)+cons;
        }
        for(auto rw2:fishies[i]) {
            ll K=likehell[b].sec(rw2-1)-ones(i,rw2-1);
            dp[i][0][rw2-1]=max(dp[i][0][rw2-1],ones(i+1,rw2-1)+K);
        }
        b=!b;
        likehell[b].init(i);
    }
    return likehell[b].overal(0);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 146 ms 77156 KB Output is correct
2 Correct 158 ms 86268 KB Output is correct
3 Correct 91 ms 68432 KB Output is correct
4 Correct 93 ms 68436 KB Output is correct
5 Correct 426 ms 123088 KB Output is correct
6 Correct 351 ms 114640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 18268 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 92 ms 68436 KB Output is correct
2 Correct 95 ms 68552 KB Output is correct
3 Correct 120 ms 68000 KB Output is correct
4 Correct 139 ms 71504 KB Output is correct
5 Correct 144 ms 77012 KB Output is correct
6 Correct 158 ms 77140 KB Output is correct
7 Correct 152 ms 76932 KB Output is correct
8 Correct 149 ms 77144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 18264 KB 1st lines differ - on the 1st token, expected: '3', found: '2'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 18264 KB 1st lines differ - on the 1st token, expected: '3', found: '2'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 18264 KB 1st lines differ - on the 1st token, expected: '3', found: '2'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 92 ms 68436 KB Output is correct
2 Correct 95 ms 68552 KB Output is correct
3 Correct 120 ms 68000 KB Output is correct
4 Correct 139 ms 71504 KB Output is correct
5 Correct 144 ms 77012 KB Output is correct
6 Correct 158 ms 77140 KB Output is correct
7 Correct 152 ms 76932 KB Output is correct
8 Correct 149 ms 77144 KB Output is correct
9 Incorrect 182 ms 83284 KB 1st lines differ - on the 1st token, expected: '99999', found: '99998'
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 146 ms 77156 KB Output is correct
2 Correct 158 ms 86268 KB Output is correct
3 Correct 91 ms 68432 KB Output is correct
4 Correct 93 ms 68436 KB Output is correct
5 Correct 426 ms 123088 KB Output is correct
6 Correct 351 ms 114640 KB Output is correct
7 Incorrect 6 ms 18268 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
8 Halted 0 ms 0 KB -