Submission #1083839

# Submission time Handle Problem Language Result Execution time Memory
1083839 2024-09-04T09:00:51 Z lamlamlam Feast (NOI19_feast) C++17
21 / 100
22 ms 5772 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
struct node
{
    int pre_max,pre_min,suf_max,suf_min,best,worst;
};
node rev(node x)
{
    x.pre_max *= -1;
    x.pre_min *= -1;
    x.suf_max *= -1;
    x.suf_min *= -1;
    x.best *= -1;
    x.worst *= -1;
    swap(x.pre_max,x.pre_min);
    swap(x.suf_max,x.suf_min);
    swap(x.best,x.worst);
    return x;
}
const int MN = 3e5+5,inf = 1e18;
int n,k,a[MN],pre[MN];
void sub34()
{
    int l,r,cur_max,res = 0;
    while(k--){
        for(int i=1; i<=n; i++) pre[i] = a[i] + pre[i-1];
        cur_max = 0;
        for(int i=1; i<=n; i++){
            for(int j=i; j<=n; j++){
                if(pre[j]-pre[i-1] > cur_max){
                    cur_max = pre[j] - pre[i-1];
                    l = i;
                    r = j;
                }
            }
        }
        if(cur_max==0) break;
        for(int i=l; i<=r; i++) res += a[i],a[i] = -a[i];
    }
    cout << res;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #define task "sus"
    if(fopen(task".inp","r")){
        freopen(task".inp","r",stdin);
        freopen(task".out","w",stdout);
    }
    cin >> n >> k;
    for(int i=1; i<=n; i++) cin >> a[i];
    if(n<=300) return sub34(),0;
    cerr << "\nTime: " << clock();
}

Compilation message

feast.cpp: In function 'int main()':
feast.cpp:51:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |         freopen(task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
feast.cpp:52:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |         freopen(task".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 5456 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 3672 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 5772 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 2 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 2 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Incorrect 1 ms 348 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 5456 KB Output isn't correct
2 Halted 0 ms 0 KB -