답안 #627056

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
627056 2022-08-12T06:03:02 Z nihaddhuseynli 메기 농장 (IOI22_fish) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#define MAX 300001
#define INF 10000000001
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define ins insert
#define f first
#define s second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
ll n,t,r,m,k,res,x,y,sum;
string s;
set<pll> a[MAX];
set<ll> b[MAX];
bool comp(tuple <ll,ll,ll> x,tuple<ll,ll,ll> y){
    return get<0>(x)>get<0>(y);
}
void solve(){
    ll dp[n+1];
    dp[0]=0;
    dp[1]=0;
    ll h=n,sum=0;
    if(b[0].size()!=0){
        h=*b[0].begin();
        for(auto x:a[0]){
            sum+=x.second;
        }
        dp[1]=sum;
    }
    for(int i=2;i<=n;i++){
        dp[i]=dp[i-1];
        if(b[i-1].size()!=0){
            ll j;
            sum=0;
            j=distance(b[i-1].begin(),b[i-1].lower_bound(h-1));
            if(j==0){
                h=n;
            }
            else{
                h=*b[i-1].begin();
            }
            auto it=a[i-1].begin();
            ll z=0;
            while(it!=a[i-1].end() && z<j){
                dp[i]+=(*it).second;
                ++it;
                z++;
            }
            sum=0;
            for(auto x:a[i-1]){
                sum+=x.second;
            }
            if(sum+dp[i-2]>dp[i]){
                dp[i]=sum+dp[i-2];
                h=*b[i-1].begin();
            }
        }
        else{
            h=n;
        }
    }
    cout << dp[n] << "\n";
}
int main(){
    t=1;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //cin >> t;
    while(t--){
        cin >> n >> m;
        for(int i=0;i<m;i++){
            ll k1,k2,k3;
            cin >> k1 >> k2 >> k3;
            a[k1].insert(make_pair(n-k2-1,k3));
            b[k1].insert(n-k2-1);
        }
        solve();
    }
}

Compilation message

/usr/bin/ld: /tmp/cckaoXb6.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccHUkRea.o:fish.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/cckaoXb6.o: in function `main':
grader.cpp:(.text.startup+0x25e): undefined reference to `max_weights(int, int, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status