제출 #33937

#제출 시각아이디문제언어결과실행 시간메모리
33937petilSplit the sequence (APIO14_sequence)C++14
컴파일 에러
0 ms0 KiB

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct CHT{
    struct line{
        ll s, t;
        int idx;
    };
    deque<line> que;
    bool ck(line L1, line L2, line me){
        ///x1 =   (L1.t-L2.t) /(L2.s-L1.s)
        ///x2 =   (L2.t - me.t) / (me.s-L2.s)
        ///x1<x2
        return (L1.t-L2.t) * (me.s-L2.s) < (L2.t-me.t) * (L2.s-L1.s) ;
    }
 
    void push(line me){
 
        while((int)que.size()>=2 && !ck(que[(int)que.size()-2], que.back(), me)){
            que.pop_back();
        }
        if(!que.empty() && que.back().s == me.s){
            if(que.back().t>=me.t)return;
            que.pop_back();que.push_back(me);
        }
        else{
            que.push_back(me);
        }
    }
    ll val(line li, ll x)
    {
        return li.s * x + li.t;
    }
    void Efront(ll x)
    {
        while((int)que.size()>=2 && !(val(que[0], x)>val(que[1], x))){
          //  if(que[1].idx == id)return;
            que.pop_front();
        }
    }
    ll maxval(ll x){
        return val(que[0], x);
    }
 
};
 
int n, k, A[100005];
ll s[100005], dp[100005][2];
int pre[100003][202];
void trace(int now, int j)
{
    vector<int> tmp;
    while(1){
        if(j==0)break;
        tmp.push_back(now);
        now = pre[now][j];--j;
    }
    for(int i=(int)tmp.size()-1; i>=0; i--)
        cout<<tmp[i]<<" ";
}
int main()
{
    scanf("%d %d", &n, &k);
    for(int i=1; i<=n; i++){
        scanf("%d", &A[i]);
    }
   for(int i=1; i<=n; i++){
        s[i] = s[i-1] + A[i];
   }
 
 
    for(int j=1; j<=k; j++){
        CHT cht;
        int pos = 0;
        int t = (j&1);
        for(int i=j; i<=n; i++){
                 cht.Efront(s[i]);
            cht.push({s[i-1], -s[i-1]*s[n] + dp[i-1][!t], i-1});
       ///     cht.Efront(s[i]);
            dp[i][t] = cht.maxval(s[i]) + s[i]*(s[n]-s[i]);
            pre[i][j] = cht.que[0].idx;
        }
 
    }
    ll ans=-1, ed=-1;
    for(int i=k; i<=n; i++){
        if(ans<dp[i][k&1]){
            ans = dp[i][k&1];ed=i;
        }
    }
 
    cout<<ans<<endl;
 
    trace(ed, k);
}

컴파일 시 표준 에러 (stderr) 메시지

sequence.cpp:17:1: error: stray '\302' in program
  
 ^
sequence.cpp:17:1: error: stray '\240' in program
sequence.cpp:19:1: error: stray '\302' in program
  
 ^
sequence.cpp:19:1: error: stray '\240' in program
sequence.cpp:45:1: error: stray '\302' in program
  
 ^
sequence.cpp:45:1: error: stray '\240' in program
sequence.cpp:47:1: error: stray '\302' in program
  
 ^
sequence.cpp:47:1: error: stray '\240' in program
sequence.cpp:71:1: error: stray '\302' in program
  
 ^
sequence.cpp:71:1: error: stray '\240' in program
sequence.cpp:72:1: error: stray '\302' in program
  
 ^
sequence.cpp:72:1: error: stray '\240' in program
sequence.cpp:84:1: error: stray '\302' in program
  
 ^
sequence.cpp:84:1: error: stray '\240' in program
sequence.cpp:92:1: error: stray '\302' in program
  
 ^
sequence.cpp:92:1: error: stray '\240' in program
sequence.cpp:94:1: error: stray '\302' in program
  
 ^
sequence.cpp:94:1: error: stray '\240' in program
sequence.cpp: In function 'int main()':
sequence.cpp:75:13: warning: unused variable 'pos' [-Wunused-variable]
         int pos = 0;
             ^
sequence.cpp:64:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &k);
                           ^
sequence.cpp:66:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &A[i]);
                           ^