Submission #611260

# Submission time Handle Problem Language Result Execution time Memory
611260 2022-07-29T04:19:47 Z talant117408 Homecoming (BOI18_homecoming) C++17
0 / 100
1000 ms 55940 KB
#include "homecoming.h"
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

#define long                unsigned long 
#define pb                  push_back
#define mp                  make_pair
#define all(v)              (v).begin(),(v).end()
#define rall(v)             (v).rbegin(),(v).rend()
#define lb                  lower_bound
#define ub                  upper_bound
#define sz(v)               int((v).size())
#define do_not_disturb      ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl                '\n'
#define PI                  2*acos(0.0)

ll solve(int n, int k, int *a, int *b) {
    vector <ll> prize(n + 1), books(n * 2 + 1), profit(n + 1), pref(n * 2 + 1);
    vector <vector <ll>> dp(n + 1, vector <ll> (2, -1e18));
    for (int i = 1; i <= n; i++) {
        prize[i] = a[i - 1];
        books[i] = b[i - 1]; 
        books[i + n] = b[i - 1];
    }
    for (int i = 1; i <= n * 2; i++) {
        pref[i] = books[i] + pref[i - 1];
    }
    for (int i = 1; i <= n; i++) {
        profit[i] = prize[i] - pref[i + k - 1] + pref[i - 1];
    }
    dp[1][1] = profit[1];
    for (int i = 2; i <= n; i++) {
        dp[i][1] = profit[i];
        for (int j = i - 1; j >= 1; j--) {
            dp[i][0] = max(dp[i][0], max(dp[j][0], dp[j][1]));
            if (i - j >= k) {
                dp[i][1] = max(dp[i][1], max(dp[j][0], dp[j][1]) + profit[i]);
            }
            else {
                dp[i][1] = max(dp[i][1], max(dp[j][0], dp[j][1] + pref[j + k - 1] - pref[i - 1]) + profit[i]);
            }
        }
    }
    ll ans = -1e18;
    for (int i = 1; i <= n; i++) {
        ans = max(ans, max(dp[i][0], dp[i][1]));
    }
    return ans;
}

//~ void solve(int test) {
//~ }  

//~ int main() {
    //~ do_not_disturb
    
    //~ int t = 1;
    //~ cin >> t;
    //~ for (int i = 1; i <= t; i++) {
        //~ solve(i);
    //~ }
    
    //~ return 0;
//~ }
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1062 ms 55940 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -