Submission #1084423

#TimeUsernameProblemLanguageResultExecution timeMemory
1084423_rain_Discharging (NOI20_discharging)C++14
9 / 100
9 ms3164 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define fixbug true const ll INF = (ll)1e18+7; const int maxn = 1e5; ll a[maxn+2] ; int n; namespace subtask1{ bool check(){ return n <= 1500; } const int N = 1500; ll f[N+2] , sum[N+2] = {}; void main_code(){ for (int i = 1; i <= n; ++i) f[i] = INF ; for (int i = 1; i <= n; ++i){ ll mx = a[i]; for (int j = i; j >= 1; --j){ mx = max(mx , a[j]); //ll v = f[j - 1] + sum[j - 1] * i - sum[j - 1] * (j + 1) + mx * i - mx * (j + 1); ll v = f[j - 1] + (sum[j - 1] + mx) * (i - j + 1); if (f[i] == v){ sum[i] = min(sum[i] , sum[j - 1] + mx); } else if (f[i] > v) { f[i] = v; sum[i] = sum[j - 1] + mx; } } } cout << f[n]; return; } } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define name "main" if (fopen(name".inp","r")){ freopen(name".inp","r",stdin); } cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; if (subtask1::check()) { subtask1::main_code(); exit(0); } //subtask2::main_code(); exit(0); }

Compilation message (stderr)

Discharging.cpp: In function 'int main()':
Discharging.cpp:45:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |         freopen(name".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#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...