Submission #413089

# Submission time Handle Problem Language Result Execution time Memory
413089 2021-05-28T08:31:33 Z Theo830 Homecoming (BOI18_homecoming) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
//#include <homecoming.h>
using namespace std;
typedef long long ll;
ll INF = 1e9+7;
ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ll,ii>
#define f(i,a,b) for(ll i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///Training
ll dp[5005][5005];
ll n,k;
ll a[5005],b[5005];
ll DP(ll last,ll idx){
    if(idx == n+1){
        return 0;
    }
    if(dp[last][idx] != -1){
        return dp[last][idx];
    }
    ll thelo = 0;
    ll END = (idx - 1 + k - 1) % n;
    ll posa = 0;
    if(last != 0){
        posa = max(0LL,k - idx + last);
    }
    ll cur = idx-1;
    while(1){
        thelo += (posa == 0) * b[cur];
        if(cur == END){
            break;
        }
        cur++;
        if(cur == n){
            cur = 0;
        }
        if(posa > 0){
            posa--;
        }
    }
    ll ans = max(DP(last,idx+1),DP(idx,idx+1) + a[idx-1] - thelo);
    return dp[last][idx] = ans;
}
long long int solve(int N, int K, int *A, int *B){
    n = N;
    k = K;
    f(i,0,n){
        a[i] = A[i];
        b[i] = B[i];
    }
    f(i,0,n+1){
        f(j,0,n+1){
            dp[i][j] = -1;
        }
    }
    return DP(0,1);
}
#ifndef __HOMECOMING_H
#define __HOMECOMING_H
#include <cstdio>
#include <cassert>

long long solve(int N, int K, int *A, int *B);

int main() {
  int T; assert(scanf("%d", &T) == 1);
  for(int t = 0; t < T; t++) {
    int N, K; assert(scanf("%d%d", &N, &K) == 2);
    int *A = new int[N];
    int *B = new int[N];
    for(int i = 0; i < N; i++) assert(scanf("%d", &A[i]) == 1);
    for(int i = 0; i < N; i++) assert(scanf("%d", &B[i]) == 1);
    printf("%lld\n", solve(N, K, A, B));
    delete[] A;
    delete[] B;
  }
  return 0;
}
#endif

Compilation message

/usr/bin/ld: /tmp/ccjTyNqL.o: in function `main':
homecoming.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cc7y9ckN.o:grader.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status