Submission #724585

# Submission time Handle Problem Language Result Execution time Memory
724585 2023-04-15T15:17:04 Z TimDee Homecoming (BOI18_homecoming) C++17
13 / 100
1000 ms 31632 KB
//   you're already the best
//             _
//   ^ ^      //
// >(O_O)<___//
//   \ __ __  \
//    \\ \\ \\\\

#include "homecoming.h"
#include <bits/stdc++.h>
using namespace std;
 
#pragma GCC optimize("O3","unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

using ll = long long;
//#define int long long
//#define double long double
#define forn(i,n) for(int i=0; i<(n); ++i)
#define pb push_back
#define pi pair<int,int>
#define f first
#define s second 
#define vii(a,n) vector<int> a(n); forn(i,n) cin>>a[i];
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int inf = 1e18;
const int mod = 998244353;

void shift(vector<ll>&a) {
    int t=a[0];
    forn(i,a.size()-1) a[i]=a[i+1];
    a[a.size()-1]=t;
}

long long solve(int N, int K, int *A, int *B) {
    #define int long long
    const int inf = 1e18;

    int ans=0;
    int n=N, k=K;
    vector<int> a(n), b(n);
    forn(i,n) a[i]=A[i], b[i]=B[i];
    forn(i,n) b.pb(b[i]);
    forn(it,n) {
        vector<int> dp(n+1,0);
        vector<int> pra(n+1,0), prb(2*n+1,0);
        forn(i,n) pra[i+1]=pra[i]+a[i];
        forn(i,2*n) prb[i+1]=prb[i]+b[i];
        for (int i=1; i<=n; ++i) {
            dp[i]=max(dp[i],dp[i-1]);
            for (int j=0; j<i; ++j) {
                //cout<<i<<' '<<j<<' '<<dp[j]<<' '<<pra[i]-pra[j]<<' '<<prb[i+k-1]-prb[max(j,i+k-1-n)]<<'\n';
                dp[i]=max(dp[i],dp[j]+(pra[i]-pra[j])-(prb[i+k-1]-prb[max(j,i+k-1-n)]));
            }
            //cout<<dp[i]<<'\n';
        }
        //cout<<'\n';
        ans=max(ans,dp[n]);
        shift(a),shift(b);
    }
    return ans;

    #undef int
}

Compilation message

homecoming.cpp:5:1: warning: multi-line comment [-Wcomment]
    5 | //   \ __ __  \
      | ^
homecoming.cpp:28:17: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   28 | const int inf = 1e18;
      |                 ^~~~
homecoming.cpp: In function 'void shift(std::vector<long long int>&)':
homecoming.cpp:18:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 | #define forn(i,n) for(int i=0; i<(n); ++i)
      |                                 ^
homecoming.cpp:33:5: note: in expansion of macro 'forn'
   33 |     forn(i,a.size()-1) a[i]=a[i+1];
      |     ^~~~
homecoming.cpp: In function 'long long int solve(int, int, int*, int*)':
homecoming.cpp:39:15: warning: unused variable 'inf' [-Wunused-variable]
   39 |     const int inf = 1e18;
      |               ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 77 ms 352 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 83 ms 460 KB Output is correct
5 Correct 9 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 77 ms 352 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 83 ms 460 KB Output is correct
5 Correct 9 ms 340 KB Output is correct
6 Execution timed out 1068 ms 724 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1073 ms 31632 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 77 ms 352 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 83 ms 460 KB Output is correct
5 Correct 9 ms 340 KB Output is correct
6 Execution timed out 1068 ms 724 KB Time limit exceeded
7 Halted 0 ms 0 KB -