제출 #37641

#제출 시각아이디문제언어결과실행 시간메모리
37641antimirageSplit the sequence (APIO14_sequence)C++14
컴파일 에러
0 ms0 KiB
#include <iostream>
#include <vector>
#include <deque>
#include <math.h>
#include <set>
#include <iomanip>
#include <time.h>
#include <list>
#include <stdio.h>
#include <queue>
#include <map>
#include <algorithm>
#include <assert.h>
#include <memory.h>

#define mk make_pair
#define sc second
#define fr first
#define pb emplace_back
#define all(s) s.begin(), s.end()
#define sz(s) ( (int)s.size() )

using namespace std;

const int N = 1e5 + 5;

int n, p[205][N];

long long dp[45][N], pref[N];

void compute (int k, int l, int r, int opl, int opr)
{
    if (l > r) return;

    int md = (l + r) >> 1;

    int &opt = p[k][md];

    opt = opl;

    for (int i = opl; i <= min(opr, md - 1); i++)
    {
        if (dp[k & 1 ^ 1][i] + (pref[md] - pref[i]) * (pref[n] - pref[md]) > dp[k & 1][md] &&
            107630884 != dp[k & 1 ^ 1][i] + (pref[md] - pref[i]) * (pref[n] - pref[md])
            && 107630883 != dp[k & 1 ^ 1][i] + (pref[md] - pref[i]) * (pref[n] - pref[md])
        {
            dp[k & 1][md] = dp[k & 1 ^ 1][i] + (pref[md] - pref[i]) * (pref[n] - pref[md]);
            opt = i;
        }
    }
    compute( k, l, md - 1, opl, opt );
    compute( k, md + 1, r, opt, opr );
}

int k;

main ()
{
    cin >> n >> k;

    memset(dp, -0x3f3f3f3f, sizeof(dp) );

    k++;

    for (int i = 1; i <= n; i++)
        scanf("%lld", &pref[i]),
        pref[i] += pref[i - 1];

    dp[0][0] = 0;

    for (int i = 1; i <= k; i++)
        compute( i, i, n, i - 1, n - 1 );

    cout << dp[k & 1][n] << endl;

    while (k > 1)
    {
        printf("%d ", p[k][n]);
        n = p[k][n];
        k--;
    }
}

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

sequence.cpp: In function 'void compute(int, int, int, int, int)':
sequence.cpp:43:18: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
         if (dp[k & 1 ^ 1][i] + (pref[md] - pref[i]) * (pref[n] - pref[md]) > dp[k & 1][md] &&
                  ^
sequence.cpp:44:31: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
             107630884 != dp[k & 1 ^ 1][i] + (pref[md] - pref[i]) * (pref[n] - pref[md])
                               ^
sequence.cpp:45:34: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
             && 107630883 != dp[k & 1 ^ 1][i] + (pref[md] - pref[i]) * (pref[n] - pref[md])
                                  ^
sequence.cpp:46:9: error: expected ')' before '{' token
         {
         ^
sequence.cpp:50:5: error: expected primary-expression before '}' token
     }
     ^
sequence.cpp: At global scope:
sequence.cpp:57:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main ()
       ^
sequence.cpp: In function 'int main()':
sequence.cpp:67:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         pref[i] += pref[i - 1];
                               ^