Submission #1111390

# Submission time Handle Problem Language Result Execution time Memory
1111390 2024-11-12T08:05:05 Z SuperVOI Feast (NOI19_feast) C++14
51 / 100
33 ms 62544 KB
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define el '\n'
#define fu(i,a,b) for(int i = (a), _b = (b); i <= _b; ++i)
#define fd(i,a,b) for(int i = (a), _b = (b); i >= _b; --i)
#define fa(x, a) for(auto x : a)
#define re(i, n) fu(i,0,n - 1)
#define vi vector<int>
#define vvi vector<vi>
#define vll vector<ll>
#define vvll vector<vll>
#define pb push_back
#define pf push_front
#define pof pop_front
#define pob pop_back
#define sz(a) (int)(a.size())
#define all(a) a.begin(), a.end()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpii vector<pii>
#define vvpii vector<vpii>
#define vpll vector<pll>
#define vvpll vector<vpll>
#define MP make_pair
#define fi first
#define se second
#define MASK(i) (1LL << (i))
#define db double
#define ld long double
#define squr(a) 1LL * (a) * (a)

using namespace std;

const int maxn = 3e5;
const ll  lim  = 1e9;
const ll  inf  = 1e18;
const ll  mod  = 1e9 + 7; /// 1007050321
const ll  base = 33137;

template<class T1,class T2>
bool maximize(T1 &a,T2 b){
    if(a < b){
        a = b;
        return 1;
    }
    return 0;
}

template<class T1,class T2>
bool minimize(T1 &a,T2 b){
    if(a > b){
        a = b;
        return 1;
    }
    return 0;
}

template<class T1,class T2>
void Add(T1 &a,T2 b){
    a += b;
    if(a >= mod) a -= mod;
    if(a < 0) a += mod;
    return;
}

template<class T1>
void temp_compress(vector<T1> &a){
    sort(all(a));
    a.resize(unique(all(a)) - a.begin());
    return;
}

ll max(ll a,ll b){return (a > b ? a : b);}
ll min(ll a,ll b){return (a < b ? a : b);}
bool takeBit(ll th,ll n){return ((n >> th) & 1LL);}
ll gcd(ll a,ll b){return (__gcd(a, b));}

mt19937_64 rd(chrono::steady_clock::now().time_since_epoch(). count());
#define rand rd

ll ran(ll lo,ll hi){
    return (lo + rand() % (hi - lo + 1));
}

//int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
//int dy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
int dx[3] = {1, 0, 0};
int dy[3] = {0, -1, 1};

int n,m;
ll a[maxn + 5];

bool check_sub1(){
    fu(i,1,n) if(a[i] < 0) return 0;
    return 1;
}

namespace sub1 {
    void solve(){
        ll sum = 0LL;
        fu(i,1,n) sum += a[i];
        cout<<sum;
        return;
    }
}

bool check_sub2(){
    int cnt = 0;
    fu(i,1,n) if(a[i] < 0) ++cnt;
    return (cnt == 1);
}

namespace sub2 {
    void solve(){
        int pos = 0;
        fu(i,1,n) if(a[i] < 0){
            pos = i;
            break;
        }
        ll sum1 = 0LL, sum2 = 0LL;
        fu(i,1,pos - 1) sum1 += a[i];
        fu(i,pos + 1,n) sum2 += a[i];
        if(m > 1) cout<<sum1 + sum2;
        else{
            ll sum = sum1 + sum2 + a[pos];
            cout<<max({sum, sum1, sum2});
        }
        return;
    }
}

bool check_sub3(){
    return (m == 1);
}

namespace sub3 {
    void solve(){
        ll res = 0LL, sum = 0LL;
        fu(i,1,n){
            sum += a[i];
            maximize(res, sum);
            maximize(sum, 0LL);
        }
        cout<<res;
        return;
    }
}

bool check_sub5(){
    return (n <= 300);
}

namespace sub5 {
    ll dp[305][305], pre[305];

    void solve(){
        fu(i,1,n) pre[i] = pre[i - 1] + a[i];
        memset(dp, -0x3f, sizeof dp);
        fu(i,0,n) dp[i][0] = 0LL;
        re(i, n) fu(j,0,min(i, m)){
            if(j < m) maximize(dp[i][j + 1], dp[i][j]);
            maximize(dp[i + 1][j], dp[i][j]);
            if(j < m) fu(k,i + 1,n) maximize(dp[k][j + 1], dp[i][j] + pre[k] - pre[i]);
        }
        // fu(i,1,n){
        //     cout<<"Position : "<<i<<el;
        //     fu(j,1,min(i, m)) cout<<dp[i][j]<<' ';
        //     cout<<el;
        // }
        cout<<dp[n][m];
        return;
    }
}

bool check_sub6(){
    return (n <= 2000);
}

namespace sub6 {
    ll dp[2005][2005], g[2005][2005];
    void solve(){
        fu(i,1,n) fu(j,1,m){
            dp[i][j] = dp[i - 1][j] + a[i];
            if(j) maximize(dp[i][j], g[i - 1][j - 1] + a[i]);
            g[i][j] = max(g[i - 1][j], dp[i][j]);
        }
        ll res = 0LL;
        fu(j,1,m) maximize(res, dp[n][j]); 
        cout<<res;
        return;
    }
}

void input(){
    cin>>n>>m;
    fu(i,1,n) cin>>a[i];
    return;
}

int main(){
    fast
    // freopen("feas.INP", "r", stdin);
    // freopen("feas.OUT", "w", stdout);
    // clock_t start = clock();

    input();
    if(check_sub1()) return sub1::solve(), 0;
    if(check_sub2()) return sub2::solve(), 0;
    if(check_sub3()) return sub3::solve(), 0;
    if(check_sub5()) return sub5::solve(), 0;
    if(check_sub6()) return sub6::solve(), 0;

    // cerr<<el<<"Time elapsed : "<<(clock() - start)<<el;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 33 ms 4432 KB Output is correct
2 Correct 20 ms 4688 KB Output is correct
3 Correct 21 ms 4688 KB Output is correct
4 Correct 25 ms 4688 KB Output is correct
5 Correct 22 ms 4572 KB Output is correct
6 Correct 21 ms 4432 KB Output is correct
7 Correct 22 ms 4576 KB Output is correct
8 Correct 20 ms 4856 KB Output is correct
9 Correct 19 ms 4432 KB Output is correct
10 Correct 19 ms 4688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 4748 KB Output is correct
2 Correct 13 ms 4688 KB Output is correct
3 Correct 13 ms 4688 KB Output is correct
4 Correct 17 ms 4688 KB Output is correct
5 Correct 21 ms 4576 KB Output is correct
6 Correct 14 ms 4688 KB Output is correct
7 Correct 14 ms 4688 KB Output is correct
8 Correct 21 ms 4572 KB Output is correct
9 Correct 20 ms 4572 KB Output is correct
10 Correct 13 ms 4688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 4688 KB Output is correct
2 Correct 22 ms 4680 KB Output is correct
3 Correct 23 ms 4700 KB Output is correct
4 Correct 23 ms 4688 KB Output is correct
5 Correct 23 ms 4688 KB Output is correct
6 Correct 24 ms 4572 KB Output is correct
7 Correct 24 ms 4688 KB Output is correct
8 Correct 24 ms 4688 KB Output is correct
9 Correct 23 ms 4688 KB Output is correct
10 Correct 24 ms 4688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2552 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 2 ms 2384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2552 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 2 ms 2384 KB Output is correct
11 Correct 2 ms 2384 KB Output is correct
12 Correct 3 ms 2384 KB Output is correct
13 Correct 2 ms 2520 KB Output is correct
14 Correct 2 ms 2384 KB Output is correct
15 Correct 2 ms 2596 KB Output is correct
16 Correct 2 ms 2384 KB Output is correct
17 Correct 3 ms 2384 KB Output is correct
18 Correct 1 ms 2384 KB Output is correct
19 Correct 2 ms 2384 KB Output is correct
20 Correct 2 ms 2384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2552 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 2 ms 2384 KB Output is correct
11 Correct 2 ms 2384 KB Output is correct
12 Correct 3 ms 2384 KB Output is correct
13 Correct 2 ms 2520 KB Output is correct
14 Correct 2 ms 2384 KB Output is correct
15 Correct 2 ms 2596 KB Output is correct
16 Correct 2 ms 2384 KB Output is correct
17 Correct 3 ms 2384 KB Output is correct
18 Correct 1 ms 2384 KB Output is correct
19 Correct 2 ms 2384 KB Output is correct
20 Correct 2 ms 2384 KB Output is correct
21 Incorrect 7 ms 62544 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 33 ms 4432 KB Output is correct
2 Correct 20 ms 4688 KB Output is correct
3 Correct 21 ms 4688 KB Output is correct
4 Correct 25 ms 4688 KB Output is correct
5 Correct 22 ms 4572 KB Output is correct
6 Correct 21 ms 4432 KB Output is correct
7 Correct 22 ms 4576 KB Output is correct
8 Correct 20 ms 4856 KB Output is correct
9 Correct 19 ms 4432 KB Output is correct
10 Correct 19 ms 4688 KB Output is correct
11 Correct 12 ms 4748 KB Output is correct
12 Correct 13 ms 4688 KB Output is correct
13 Correct 13 ms 4688 KB Output is correct
14 Correct 17 ms 4688 KB Output is correct
15 Correct 21 ms 4576 KB Output is correct
16 Correct 14 ms 4688 KB Output is correct
17 Correct 14 ms 4688 KB Output is correct
18 Correct 21 ms 4572 KB Output is correct
19 Correct 20 ms 4572 KB Output is correct
20 Correct 13 ms 4688 KB Output is correct
21 Correct 22 ms 4688 KB Output is correct
22 Correct 22 ms 4680 KB Output is correct
23 Correct 23 ms 4700 KB Output is correct
24 Correct 23 ms 4688 KB Output is correct
25 Correct 23 ms 4688 KB Output is correct
26 Correct 24 ms 4572 KB Output is correct
27 Correct 24 ms 4688 KB Output is correct
28 Correct 24 ms 4688 KB Output is correct
29 Correct 23 ms 4688 KB Output is correct
30 Correct 24 ms 4688 KB Output is correct
31 Correct 1 ms 2384 KB Output is correct
32 Correct 1 ms 2384 KB Output is correct
33 Correct 1 ms 2384 KB Output is correct
34 Correct 1 ms 2384 KB Output is correct
35 Correct 1 ms 2552 KB Output is correct
36 Correct 1 ms 2384 KB Output is correct
37 Correct 1 ms 2384 KB Output is correct
38 Correct 1 ms 2384 KB Output is correct
39 Correct 1 ms 2384 KB Output is correct
40 Correct 2 ms 2384 KB Output is correct
41 Correct 2 ms 2384 KB Output is correct
42 Correct 3 ms 2384 KB Output is correct
43 Correct 2 ms 2520 KB Output is correct
44 Correct 2 ms 2384 KB Output is correct
45 Correct 2 ms 2596 KB Output is correct
46 Correct 2 ms 2384 KB Output is correct
47 Correct 3 ms 2384 KB Output is correct
48 Correct 1 ms 2384 KB Output is correct
49 Correct 2 ms 2384 KB Output is correct
50 Correct 2 ms 2384 KB Output is correct
51 Incorrect 7 ms 62544 KB Output isn't correct
52 Halted 0 ms 0 KB -