답안 #1026369

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1026369 2024-07-18T03:07:38 Z Mardonbekhazratov 메기 농장 (IOI22_fish) C++17
9 / 100
57 ms 10860 KB
#include "fish.h"

#include <iostream>
#include <vector>
#include <tuple>
#include <set>
#include <algorithm>
#include <map>

using namespace std;

#define ff first
#define ss second
#define ll long long

template<typename T,typename S>
T max(T a,S b){return a>b?a:b;}

int n,m;
vector<int>x,y,w;
ll ans=0;

ll sub2(){
    ll cur=0;
        if(n==2){
            for(int i=0;i<m;i++){
                if(x[i]) cur+=w[i];
                else ans+=w[i];
            }
            return max(ans,cur);
        }
        vector<pair<int,int>>a,b;
        for(int i=0;i<m;i++){
            if(x[i]&1) cur+=w[i],a.push_back({y[i],w[i]});
            else b.push_back({y[i],w[i]});
        }
        sort(a.begin(),a.end());
        sort(b.begin(),b.end());
        ans=cur;
        int j=0;
        for(auto [g,f]:b){
            cur+=f;
            while(j<a.size() && a[j].ff<=g) cur-=a[j].ss,j++;
            ans=max(ans,cur);
        }
        return ans;
}

ll sub3(){
    vector<pair<int,int>>a;
    for(int i=0;i<m;i++) a.push_back({x[i],w[i]});
    a.push_back({n,0});
    sort(a.begin(),a.end());
    int last=-1;
    vector<int>b={0};
    for(int i=0;i<=m;i++){
        if(a[i].ff-last==1) b.push_back(a[i].ss);
        else{
            ll cur=0;
            vector<ll>pref(b.size()+1),suff(b.size()+2);
            pref[0]=0;
            suff[b.size()+1]=0;
            for(int i=1;i<=b.size();i++){
                pref[i]=pref[i-1];
                if(i>2){
                    pref[i]=max(pref[i],pref[i-3]+b[i-1]+b[i-3]);
                }
                else{
                    pref[i]=max(pref[i],b[i-1]);
                }
            }
            for(int i=b.size();i>0;i--){
                suff[i]=suff[i+1];
                if(b.size()-i>1){
                    suff[i]=max(suff[i],suff[i+3]+b[i-1]+b[i+1]);
                }
                else{
                    suff[i]=max(suff[i],b[i-1]);
                }
            }
            for(int i=0;i<=b.size();i++) cur=max(pref[i],suff[i+1]);
            ans+=cur;
            vector<int>ne;
            swap(ne,b);
            b.push_back(a[i].ss);
        }
        last=a[i].ff;
    }
    
            ll cur=0;
            vector<ll>pref(b.size()+1),suff(b.size()+2);
            pref[0]=0;
            suff[b.size()+1]=0;
            for(int i=1;i<=b.size();i++){
                pref[i]=pref[i-1];
                if(i>2){
                    pref[i]=max(pref[i],pref[i-3]+b[i-1]+b[i-3]);
                }
                else{
                    pref[i]=max(pref[i],b[i-1]);
                }
            }
            for(int i=b.size();i>0;i--){
                suff[i]=suff[i+1];
                if(b.size()-i>1){
                    suff[i]=max(suff[i],suff[i+3]+b[i-1]+b[i+1]);
                }
                else{
                    suff[i]=max(suff[i],b[i-1]);
                }
            }
            for(int i=0;i<=b.size();i++) cur=max(pref[i],suff[i+1]);
            ans+=cur;
    return ans;
}

long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> W) {
    tie(n,m,x,y,w)=tie(N,M,X,Y,W);
    bool su1=true,su2=true,su3=true;
    for(int i=0;i<m;i++){
        if(x[i]%2==1) su1=false;
        if(x[i]>1) su2=false;
        if(y[i]!=0) su3=false;
    }
    if(su1){for(int i=0;i<m;i++) ans+=w[i];return ans;}
    if(su2) return sub2();
    if(su3) return sub3();
    return ans;
}

Compilation message

fish.cpp: In function 'long long int sub2()':
fish.cpp:43:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |             while(j<a.size() && a[j].ff<=g) cur-=a[j].ss,j++;
      |                   ~^~~~~~~~~
fish.cpp: In function 'long long int sub3()':
fish.cpp:63:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |             for(int i=1;i<=b.size();i++){
      |                         ~^~~~~~~~~~
fish.cpp:81:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |             for(int i=0;i<=b.size();i++) cur=max(pref[i],suff[i+1]);
      |                         ~^~~~~~~~~~
fish.cpp:94:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |             for(int i=1;i<=b.size();i++){
      |                         ~^~~~~~~~~~
fish.cpp:112:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  112 |             for(int i=0;i<=b.size();i++) cur=max(pref[i],suff[i+1]);
      |                         ~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 3160 KB Output is correct
2 Correct 17 ms 3928 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 53 ms 10860 KB Output is correct
6 Correct 54 ms 10856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 41 ms 7620 KB Output is correct
3 Correct 57 ms 9160 KB Output is correct
4 Correct 14 ms 3164 KB Output is correct
5 Correct 17 ms 3932 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 360 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 20 ms 4308 KB Output is correct
13 Correct 24 ms 5076 KB Output is correct
14 Correct 26 ms 4204 KB Output is correct
15 Correct 29 ms 4568 KB Output is correct
16 Correct 20 ms 4312 KB Output is correct
17 Correct 23 ms 4568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 18 ms 3000 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '19834199418157'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '3', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '3', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '3', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 18 ms 3000 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '19834199418157'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 3160 KB Output is correct
2 Correct 17 ms 3928 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 53 ms 10860 KB Output is correct
6 Correct 54 ms 10856 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 41 ms 7620 KB Output is correct
9 Correct 57 ms 9160 KB Output is correct
10 Correct 14 ms 3164 KB Output is correct
11 Correct 17 ms 3932 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 360 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 20 ms 4308 KB Output is correct
19 Correct 24 ms 5076 KB Output is correct
20 Correct 26 ms 4204 KB Output is correct
21 Correct 29 ms 4568 KB Output is correct
22 Correct 20 ms 4312 KB Output is correct
23 Correct 23 ms 4568 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Incorrect 18 ms 3000 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '19834199418157'
27 Halted 0 ms 0 KB -