Submission #1263405

#TimeUsernameProblemLanguageResultExecution timeMemory
1263405baodatFeast (NOI19_feast)C++20
0 / 100
1 ms328 KiB
///Old is gold, and gold is great. So old is great!
/*
This bozo is cheating, plz ban him cfs!!!!!
bozo: top1severtin
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ull unsigned long long int
#define eb emplace_back
#define ins insert
#define pb push_back
#define popcount(x) __builtin_popcountll(x)
#define clz(x) __builtin_clz(x)
#define ctz(x) __builtin_ctz(x)
#define MASK(x) (1ll << x)
#define all(x) (x).begin(), (x).end()
#define	all_rev(x) (x).rbegin(), (x).rend()
#define FOR(i, l, r) for(int i = (int)(l), _ = (int)(r); i <= _; i++)
#define FORD(i, l, r) for(int i = (int)(l), _ = (int)(r); i >= _; i--)
#define SFOR(i, l, r, x) for(int i = (int)(l), _ = (int)(r); i <= _; i += (x))
#define SFORD(i, l, r, x) for(int i = (int)(l), _ = (int)(r); i >= _; i -= (x))
#define db double
#define ldb long double
#define ms(x, val) memset(x, val, sizeof(x))
#define sp(x) setprecision(x) << fixed
#define ff first
#define ss second
#define rsz resize
#define el "\n"
#define coding24_7_simulator signed main(void)
#define div ______div
template<typename T> void debug_1d(const T& a, const string& name) {
	if(a.empty()) {
		cerr << name << " is empty!\n";
		return;
	}
	FOR(i, 0, a.size() - 1) {
		cerr << name << "[" << i << "]: " << a[i] << el;
	}
}
template<typename T> void debug_2d(const T& a, const string& name) {
	if(a.empty()) {
		cerr << name << "is empty!\n";
		return;
	}
	FOR(i, 0, a.size() - 1) {
		if(a[i].empty()) {
			cerr << name << "[" << i << "] is empty!\n";
			continue;
		}
		FOR(j, 0, a[i].size() - 1) {
			cerr << name << "[" << i << "]" << "[" << j << "]: " << a[i][j] << " ";
		}
		cerr << el;
	}
}
template<typename T> void debug_var(const T& a, const string& name) {
	cerr << name << ": " << a << el;
}
template<typename T> void debug_map(const T& a, const string& name) {
	if(a.empty()) {
		cerr << name << " is empty!\n";
		return;
	}
	for(const auto& it : a) {
		cerr << name << "[" << it.ff << "]: " << it.ss << el;
	}
}
template<typename T> void debug_stack(stack<T> s, const string& name) {
	if (s.empty()) {
		cerr << name << " is empty!\n";
		return;
	}
	int idx = 0;
	while (!s.empty()) {
		cerr << name << "[" << idx++ << "]: " << s.top() << '\n';
		s.pop();
	}
}

template<typename T> void debug_queue(queue<T> q, const string& name) {
	if (q.empty()) {
		cerr << name << " is empty!\n";
		return;
	}
	int idx = 0;
	while (!q.empty()) {
		cerr << name << "[" << idx++ << "]: " << q.front() << '\n';
		q.pop();
	}
}
template<typename T> void debug_pq(priority_queue<T> pq, const string& name) {
	if (pq.empty()) {
		cerr << name << " is empty!\n";
		return;
	}
	int idx = 0;
	while (!pq.empty()) {
		cerr << name << "[" << idx++ << "]: " << pq.top() << '\n';
		pq.pop();
	}
}
void read_file() {
#define NAME "txt"
	freopen(NAME ".INP", "r", stdin);
	freopen(NAME ".OUT", "w", stdout);
}
void ifndef_read_file(){
#define NAME2 "read"
    #ifndef ONLINE_JUDGE
    freopen(NAME2 ".INP", "r", stdin);
    freopen(NAME2 ".OUT", "w", stdout);
    #endif // ONLINE_JUDGE
}
typedef __int128 i128;
typedef pair<int, int> pii;
typedef pair<char, int> pci;
typedef pair<int, char> pic;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<vector<int>> vector2d_int;
typedef vector<vector<char>> vector2d_char;
const long long oo = 2e18;
const int oo_int = 2e9;
const int mod = 1e9 + 7;
const int mod998 = 998244353;
void prepare(){
}
void solve() {
    int n, k;
    cin >> n >> k;
    if(n > 5e3 || k > 5e3) return;
    vector<int>a(n + 1);
    FOR(i, 1, n) cin >> a[i];
    vector2d_int dp_in(n + 1, vector<int>(k + 1, -oo));
    vector2d_int dp_out(n + 1, vector<int>(k + 1, -oo));
    dp_out[0][0] = 0;
    FOR(i, 1, n)FOR(t, 0, k){
        dp_out[i][t] = max(dp_out[i - 1][t], dp_in[i - 1][t]);
        if(dp_in[i - 1][t] != -oo){
            dp_in[i][t] = max(dp_in[i][t], dp_in[i - 1][t] + a[i]);
        }
        if(t > 0 && dp_out[i - 1][t - 1] != -oo){
            dp_in[i][t] = max(dp_in[i][t], dp_out[i - 1][t - 1] + a[i]);
        }
    }
    int ans = -oo;
    FOR(i, 0, k) ans = max({ans, dp_in[n][i], dp_out[n][i]});
    cout << ans << el;
}
coding24_7_simulator {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	//read_file();
	ifndef_read_file();
	prepare();
	int t = 1;
	//cin >> t;
	while(t--)
		solve();
	return 0;
}

Compilation message (stderr)

feast.cpp: In function 'void read_file()':
feast.cpp:106:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  106 |         freopen(NAME ".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
feast.cpp:107:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  107 |         freopen(NAME ".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
feast.cpp: In function 'void ifndef_read_file()':
feast.cpp:112:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  112 |     freopen(NAME2 ".INP", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
feast.cpp:113:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  113 |     freopen(NAME2 ".OUT", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...