답안 #834379

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
834379 2023-08-22T13:48:15 Z gagik_2007 메기 농장 (IOI22_fish) C++17
0 / 100
28 ms 8852 KB
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
#define ff first
#define ss second
 
ll ttt;
const ll INF=1e18;
const ll MOD=1e9+7;
const ll N=3007;
ll n,m,k;
ll pf[N][5]; // minchev j-rdy gumary
ll dp[N][5][5];
vector<pair<int,ll>>g[N];

int vorna_ste(int col, int row){
    if(col<0||col>=n)return 0;
    for(int i=0;i<g[col].size();i++){
        if(g[col][i].ff>row){
            return i;
        }
    }
    return g[col].size();
}

ll max_weights(int NN, int MM, vector<int> X, vector<int> Y, vector<int> W) {
    n=NN;
    m=MM;
    for(int i=0;i<m;i++){
        g[X[i]].push_back({Y[i],W[i]});
    }
    for(int i=0;i<n;i++){
        g[i].push_back({n,0});
        sort(g[i].begin(),g[i].end());
        for(int j=0;j<g[i].size();j++){
            pf[i][j+1]=g[i][j].ss;
            pf[i][j+1]+=pf[i][j];
        }
    }
    for(int i=0;i<g[0].size();i++){
        // cout<<dp[0][1][1]<<endl;
        dp[0][0][i]=pf[1][vorna_ste(1,g[0][i].ff-1)];
        // cout<<"0, 0, "<<i<<": "<<dp[0][0][i]<<endl;
    }
    // cout<<endl;
    ll ans=0;
    for(int i=1;i<n;i++){
        for(int j=0;j<g[i].size();j++){
            for(int k=0;k<g[i-1].size();k++){
                // cout<<i<<", "<<k<<", "<<j<<": ";
                for(int p=0;p<(i-2>=0?g[i-2].size():1);p++){
                    ll res=dp[i-1][p][k];
                    res-=pf[i][vorna_ste(i,min(g[i-1][k].ff,g[i][j].ff)-1)];
                    if(j>p&&j>k){
                        res+=pf[i-1][vorna_ste(i-1,g[i][j].ff-1)]
                            -pf[i-1][vorna_ste(i-1,
                            max((i-2>=0?g[i-2][p].ff:0),g[i-1][k].ff)-1)];
                    }
                    if(i!=n-1){
                        res+=pf[i+1][vorna_ste(i+1,g[i][j].ff-1)];
                    }
                    dp[i][k][j]=max(dp[i][k][j],res);
                }
                ans=max(ans,dp[i][k][j]);
                // cout<<dp[i][k][j]<<"\n";
            }
            // cout<<endl;
        }
        // cout<<endl;
    }
    return ans;
}

Compilation message

fish.cpp: In function 'int vorna_ste(int, int)':
fish.cpp:24:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     for(int i=0;i<g[col].size();i++){
      |                 ~^~~~~~~~~~~~~~
fish.cpp: In function 'll max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:41:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |         for(int j=0;j<g[i].size();j++){
      |                     ~^~~~~~~~~~~~
fish.cpp:46:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     for(int i=0;i<g[0].size();i++){
      |                 ~^~~~~~~~~~~~
fish.cpp:54:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |         for(int j=0;j<g[i].size();j++){
      |                     ~^~~~~~~~~~~~
fish.cpp:55:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |             for(int k=0;k<g[i-1].size();k++){
      |                         ~^~~~~~~~~~~~~~
fish.cpp:57:30: warning: comparison of integer expressions of different signedness: 'int' and 'long unsigned int' [-Wsign-compare]
   57 |                 for(int p=0;p<(i-2>=0?g[i-2].size():1);p++){
      |                             ~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 28 ms 8852 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 980 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 372 KB 1st lines differ - on the 1st token, expected: '3', found: '2'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 372 KB 1st lines differ - on the 1st token, expected: '3', found: '2'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 372 KB 1st lines differ - on the 1st token, expected: '3', found: '2'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 980 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 28 ms 8852 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -