Submission #880966

#TimeUsernameProblemLanguageResultExecution timeMemory
880966mychecksedadSeesaw (JOI22_seesaw)C++17
1 / 100
1 ms6644 KiB
/* Author : Mychecksdead */ #include<bits/stdc++.h> using namespace std; #define ll long long int #define MOD (1000000000+7) #define MOD1 (998244353) #define pb push_back #define all(x) x.begin(), x.end() #define en cout << '\n' const int N = 3000+100, M = 1e5+10, K = 52, MX = 30; int n, a[N]; ll pref[N]; pair<double, double> dp[N][N]; pair<double, double> comp(pair<double, double> x, pair<double, double> y){ if(x.second - x.first < y.second - y.first) return x; return y; } void solve(){ cin >> n; for(int i = 1; i <= n; ++i) cin >> a[i]; pref[0] = 0; for(int i = 1; i <= n; ++i) pref[i] = pref[i - 1] + a[i]; for(int i = 0; i <= n + 1; ++i) for(int j = 0; j <= n + 1; ++j) dp[i][j] = {-1e18, 1e18}; dp[1][n] = {pref[n] / (double) n, pref[n] / (double) n}; for(int sz = n - 1; sz >= 0; --sz){ for(int l = 1; l <= n; ++l){ int r = l + sz - 1; if(r>n) break; double pos = (pref[r] - pref[l - 1]) / (double)(r-l+1); pair<double, double> v = {min(pos, dp[l][r + 1].first), max(pos, dp[l][r + 1].second)}; pair<double, double> p = {min(pos, dp[l - 1][r].first), max(pos, dp[l - 1][r].second)}; dp[l][r] = comp(v, p); } } pair<double, double> ans = {-1e18, 1e18}; for(int i = 1; i <= n; ++i) ans = comp(ans, dp[i][i]); cout << fixed << setprecision(15); cout << ans.second - ans.first; } int main(){ cin.tie(0); ios::sync_with_stdio(0); int tt = 1, aa; // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); while(tt--){ solve(); en; } cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n"; return 0; }

Compilation message (stderr)

seesaw.cpp: In function 'int main()':
seesaw.cpp:45:15: warning: unused variable 'aa' [-Wunused-variable]
   45 |   int tt = 1, aa;
      |               ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...