Submission #1124375

#TimeUsernameProblemLanguageResultExecution timeMemory
1124375seoul_koreaCandies (JOI18_candies)C++17
8 / 100
46 ms16348 KiB
#include <bits/stdc++.h> using namespace std; #define TASK "JOI18_candies" #define int long long #define REP(i, n) for(int i = 1; i <= n; i++) #define FOR(i, a, b) for(auto i = a; i <= b; i++) #define FORD(i, a, b) for(auto i = a; i >= b; i--) template<class T> bool maximize(T& a, T b) { if(a < b) return a = b, 1; return 0; } template<class T> bool minimize(T& a, T b) { if(a > b) return a = b, 1; return 0; } mt19937 rng(time(0)); const int N = (int)2e5 + 7; int a[N]; int n; namespace Subtask1 { const int maxN = 2007; int f[maxN][maxN]; bool Check() { return n <= 2000; } void Calc(int k) { REP(i, n) { if(f[i - 1][k]) f[i][k] = f[i - 1][k]; if(i - 2 > 0 && f[i - 2][k - 1]) maximize(f[i][k], f[i - 2][k - 1] + a[i]); } } void Solve() { REP(i, n) f[i][1] = max(a[i], f[i - 1][1]); REP(i, (n + 1) / 2) { if(i > 1) Calc(i); int ans = 0; REP(j, n) maximize(ans, f[j][i]); cout << ans << '\n'; } } } signed main(void) { ios_base::sync_with_stdio(false); cin.tie(nullptr); if(fopen("TASK.INP", "r")) freopen("TASK.INP", "r", stdin); if(fopen(TASK".INP", "r")) { freopen(TASK".INP", "r", stdin); freopen(TASK".OUT", "w", stdout); } cin >> n; REP(i, n) cin >> a[i]; if(Subtask1::Check()) return Subtask1::Solve(), 0; return 0; }

Compilation message (stderr)

candies.cpp: In function 'int main()':
candies.cpp:58:39: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |     if(fopen("TASK.INP", "r")) freopen("TASK.INP", "r", stdin);
      |                                ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
candies.cpp:61:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |         freopen(TASK".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
candies.cpp:62:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |         freopen(TASK".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...