Submission #152090

# Submission time Handle Problem Language Result Execution time Memory
152090 2019-09-06T10:56:31 Z evpipis Homecoming (BOI18_homecoming) C++11
31 / 100
1000 ms 23800 KB
#include "homecoming.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int len = 2e6+5;
const ll inf = 1e17;
int ar[len], br[len], n, k;
ll suf[len], sufa[len], sufb[len], mx[len], dp[len];

ll fix(int st){
    for (int i = n-1; i >= 0; i--){
        sufa[i] = ar[(st+i)%n] + sufa[i+1];
        sufb[i] = br[(st+i)%n] + sufb[i+1];
    }

    mx[n] = dp[n] = suf[n] = 0;
    for (int i = n-1; i >= 0; i--){
        dp[i] = sufa[i]-sufb[i] + mx[i+1];
        //for (int j = i+1; j <= n+1; j++)
          //  dp[i] = max(dp[i], sufa[i]-sufb[i] + sufb[j+k-1]-sufa[j]+suf[j]);

        suf[i] = max(suf[i+1], dp[i]);
        mx[i] = max(mx[i+1], sufb[i+k-1]-sufa[i]+suf[i]);
    }

    return dp[0];
}

void init(){
    for (int i = 0; i <= 2*n; i++)
        sufa[i] = sufb[i] = 0;
}

ll solve(int N, int K, int A[], int B[]){
    n = N, k = K;
    for (int i = 0; i < n; i++){
        ar[i] = A[i];
        br[i] = B[i];
    }

    init();

    int pos = 0;
    ll best = -inf;

    for (int i = 2*n-1; i >= 0; i--){
        sufa[i] = sufa[i+1] + ar[i%n];
        sufb[i] = sufb[i+1] + br[i%n];
    }

    for (int i = 0; i < n; i++){
        for (int j = i; j-i <= n-k+1; j++)
            if (sufa[i]-sufb[i] + sufb[j+k-1]-sufa[j] > best)
                best = sufa[i]-sufb[i] + sufb[j+k-1]-sufa[j], pos = i;
    }

    init();

    return max(0LL, fix(pos));
}

/*
1
3 2
40 80 100
140 0 20
*/
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 508 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 508 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 3 ms 760 KB Output is correct
7 Correct 8 ms 760 KB Output is correct
8 Correct 6 ms 504 KB Output is correct
9 Correct 25 ms 760 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1070 ms 23800 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 508 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 3 ms 760 KB Output is correct
7 Correct 8 ms 760 KB Output is correct
8 Correct 6 ms 504 KB Output is correct
9 Correct 25 ms 760 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Execution timed out 1070 ms 23800 KB Time limit exceeded
12 Halted 0 ms 0 KB -