답안 #69639

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
69639 2018-08-21T10:27:49 Z vanogam Homecoming (BOI18_homecoming) C++14
13 / 100
246 ms 94440 KB
#include<bits/stdc++.h>
#include "homecoming.h"
using namespace std;
long long a,s,d[2000002][2],f[2000002][2],g[2000002],h[2000002],j,k,l,i,n,m;
long long get(int l,int r){
    l++;r++;
    //cout<<l<<" "<<r<<" "<<g[l-1]<<" "<<g[r]<<endl;
    if(r>=l) return g[r]-g[l-1];
    else return (g[n]-g[r-1])+g[l];
}
 
int gi(int i){
    if(i>=n) i-=n;
    return i;
}
long long solve(int N,int K,int *A,int *B){
    long long s1=A[0]-B[0];
    n=N;
    k=K;
    g[1]=B[0];
    g[0]=0;
    for(i=2;i<=n;i++){
        s1+=A[i-1]-B[i-1];
        g[i]=g[i-1]+B[i-1];
    }
    if(n==k) return max(s1,0ll);
    //memset(d,~0,sizeof d);
    d[0][1]=-1000000000000000000ll;
    d[0][0]=A[0]-g[k];
    h[n-1]=A[n-1];//cout<<d[0][0]<<" "<<d[0][1]<<endl;
    d[n-1][0]=0;
    for(i=n-2;i>=n-k;i--) h[i]=h[i+1]+A[i];
    for(i=1;i<n;i++){
        if(i+k-1>=n-1) {
 
            d[n-1][0]=max(d[n-1][0],max(d[max(i-k-1,0ll)][0],d[max(i-k-1,0ll)][1])+h[i]-get(max(i,k),n-1));
            d[i][0]=0;
            d[i][1]=max(d[i-1][1],d[i-1][0]);
 
            continue;
        }
        d[i][0]=d[i-1][0]+A[i]-B[gi(i+k-1)];
        if(d[i-1][1]!=-1 && d[i-1][1]+A[i]-get(i,gi(i+k-1))>d[i][0]) {
            d[i][0]=d[i-1][1]+A[i]-get(i,gi(i+k-1));
        }
 
        d[i][1]=max(d[i-1][1],d[i-1][0]);
    }
    d[n-1][0]=max(d[n-1][0],d[n-k-1][0]+h[n-k]-get(n-1,n-1));//cout<<d[n-1][0]<<" "<<d[n-1][1]<<" "<<d[0][0]<<" "<<h[n-k]<<" "<<get(max(i,k),n-1)<<endl;
    f[0][0]=-1000000000000000000ll;
    f[0][1]=0;
    for(i=1;i<n;i++){
        f[i][0]=f[i-1][0]+A[i]-B[gi(i+k-1)];
        //cout<<i<<"* "<<-get(i,gi(i+k-1))<<endl;
        if(f[i-1][1]+A[i]-get(i,gi(i+k-1))>f[i][0]) {
 
            f[i][0]=f[i-1][1]+A[i]-get(i,gi(i+k-1));
        }
 
        f[i][1]=max(f[i-1][1],f[i-1][0]);//cout<<f[i][0]<<" "<<f[i][1]<<endl;
    }
    return (long long)(max(max(d[n-1][0],d[n-1][1]),max(f[n-1][0],f[n-1][1])));
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 392 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 392 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 644 KB Output is correct
7 Correct 3 ms 824 KB Output is correct
8 Correct 3 ms 824 KB Output is correct
9 Incorrect 4 ms 852 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 24056 KB Output is correct
2 Correct 5 ms 24056 KB Output is correct
3 Correct 246 ms 94440 KB Output is correct
4 Incorrect 5 ms 94440 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 392 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 644 KB Output is correct
7 Correct 3 ms 824 KB Output is correct
8 Correct 3 ms 824 KB Output is correct
9 Incorrect 4 ms 852 KB Output isn't correct
10 Halted 0 ms 0 KB -