Submission #656353

#TimeUsernameProblemLanguageResultExecution timeMemory
656353aSSSdDischarging (NOI20_discharging)C++14
47 / 100
363 ms205808 KiB
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int rnd(int l,int r) { return l+rng()%(r-l+1); } #define fasty ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0); #define forinc(x,a,b) for(int x=a;x<=b;x++) #define fordec(x,a,b) for(int x=a;x>=b;x--) #define iii pair<ii,int> #define fi first #define se second #define ii pair<int,int> #define getbit(x,i) ((x>>(i))&1) #define batbit(x,i) (x|(1ll<<(i))) #define tatbit(x,i) (x&~(1<<(i))) #define endl '\n' #define pb push_back #define int long long const int N = 1e6 + 10; int n, t[N]; int f[N][23]; int lg[N]; int dp[N]; int get(int l, int r) { int p = lg[r-l+1]; return max(f[l][p] , f[r - (1<<p) + 1][p]); } int cost(int j, int i) { return dp[j] + get(j+1,i)*(n-j); } int inc=1; int decc=1; main() { //freopen("task.inp" , "r" , stdin); fasty; cin >> n; forinc(i,1,n) { cin >> t[i]; f[i][0] = t[i]; } forinc(i,1,n-1) { if(t[i] > t[i+1]) inc=0; if(t[i] < t[i+1]) decc=0; } forinc(i,2,n) lg[i] = lg[i/2] + 1; forinc(j,1,20) { for(int i=1 ; i + (1<<j) - 1 <= n ; i++) { f[i][j] = max(f[i][j-1] , f[i + (1<<(j-1) )][j-1]); } } if(n<=7000) { memset(dp , 127, sizeof dp); dp[0]=0; forinc(i,1,n) { fordec(j,i-1,0) dp[i] = min(dp[i] ,cost(j,i)); } cout << dp[n]; return 0; } if(decc == 1) { int sum=0; int res = t[1] * n; cout << res << "\n"; return 0; } }

Compilation message (stderr)

Discharging.cpp:37:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   37 | main()
      | ^~~~
Discharging.cpp: In function 'int main()':
Discharging.cpp:73:13: warning: unused variable 'sum' [-Wunused-variable]
   73 |         int sum=0;
      |             ^~~
#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...