Submission #910700

#TimeUsernameProblemLanguageResultExecution timeMemory
910700cig32Seesaw (JOI22_seesaw)C++17
34 / 100
2057 ms72060 KiB
#include "bits/stdc++.h" using namespace std; #define int long long #define double long double const int MAXN = 2e5 + 10; const int MOD = 1e9 + 7; mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count()); int rnd(int x, int y) { int u = uniform_int_distribution<int>(x, y)(rng); return u; } int bm(int b, int p) { if(p==0) return 1 % MOD; int r = bm(b, p >> 1); if(p&1) return (((r*r) % MOD) * b) % MOD; return (r*r) % MOD; } int inv(int b) { return bm(b, MOD-2); } int fastlog(int x) { return (x == 0 ? -1 : 64 - __builtin_clzll(x) - 1); } void printcase(int i) { cout << "Case #" << i << ": "; } static void run_with_stack_size(void (*func)(void), size_t stsize) { char *stack, *send; stack = (char *)malloc(stsize); send = stack + stsize - 16; send = (char *)((uintptr_t)send / 16 * 16); asm volatile( "mov %%rsp, (%0)\n" "mov %0, %%rsp\n" : : "r"(send)); func(); asm volatile("mov (%0), %%rsp\n" : : "r"(send)); free(stack); } void solve(int tc) { int n; cin >> n; int a[n+1]; for(int i=1; i<=n; i++) { cin >> a[i]; } int ps[n+1]; ps[0] = 0; for(int i=1; i<=n; i++) ps[i] = ps[i-1] + a[i]; vector<pair<double, pair<int,int>> > vt; for(int i=1; i<=n; i++) { for(int j=i; j<=n; j++) { double bi = (ps[j] - ps[i-1]) * 1.0 / (j - i + 1); vt.push_back({bi, {i, j}}); } } sort(vt.begin(), vt.end()); bool dp[n+1][n+1], init[n+1][n+1]; for(int i=0; i<=n; i++) { for(int j=0; j<=n; j++) { init[i][j] = dp[i][j] = 0; } } int j = -1; double ans = 1e18; for(int i=0; i<vt.size(); i++) { j = max(j, i - 1); double l = vt[i].first; if(i > 0) { int l = vt[i-1].second.first; int r = vt[i-1].second.second; init[l][r] = 0; } bool good = 0; while(1) { for(int k=1; k<=n; k++) for(int l=k; l<=n; l++) dp[k][l] = 0; for(int k=1; k<=n; k++) { dp[k][k] = init[k][k]; } for(int len=2; len<=n; len++) { for(int k=1; k+len-1<=n; k++) { dp[k][k+len-1] = init[k][k+len-1] && (dp[k+1][k+len-1] || dp[k][k+len-2]); } } if(dp[1][n]) { good = 1; break; } if(j + 1 < vt.size()) { j++; int l = vt[j].second.first; int r = vt[j].second.second; init[l][r] = 1; } else break; } if(good) { ans = min(ans, vt[j].first - vt[i].first); } } cout << fixed << setprecision(10) << ans << '\n'; } void uwu() { ios::sync_with_stdio(0); cin.tie(0); int t = 1; //cin >> t; for(int i=1; i<=t; i++) solve(i); } int32_t main() { #ifdef ONLINE_JUDGE uwu(); #endif #ifndef ONLINE_JUDGE run_with_stack_size(uwu, 1024 * 1024 * 1024); // run with a 1 GiB stack #endif } /* g++ A.cpp -std=c++17 -O2 -o A ./A < input.txt */

Compilation message (stderr)

seesaw.cpp: In function 'void solve(long long int)':
seesaw.cpp:64:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long double, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |   for(int i=0; i<vt.size(); i++) {
      |                ~^~~~~~~~~~
seesaw.cpp:87:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long double, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |       if(j + 1 < vt.size()) {
      |          ~~~~~~^~~~~~~~~~~
seesaw.cpp:66:12: warning: unused variable 'l' [-Wunused-variable]
   66 |     double l = vt[i].first;
      |            ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...