QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#864566#4355. Seesawpatgra0 0ms8148kbC++203.7kb2025-01-20 19:13:152025-01-20 19:13:15

Judging History

你现在查看的是最新测评结果

  • [2025-01-20 19:13:15]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:8148kb
  • [2025-01-20 19:13:15]
  • 提交

answer

#include <bits/stdc++.h>

#define rep(a,b,c) for(auto a = (b); a != (c); a++)
#define repD(a,b,c) for(auto a = (b); a != (c); a--)
#define repIn(a, b) for(auto& a : (b))
#define repIn2(a, b, c) for(auto& [a, b] : (c))

constexpr bool dbg = 0;
#define DEBUG if constexpr(dbg)
#define DC DEBUG std::cerr
#define eol std::endl

#define ll long long
#define pb push_back
#define ld long double

using namespace std;

constexpr int maxn = 2e5 + 7;
constexpr ld eps = 1e-5;

int n;
ll arr[maxn];
ld bc, deviance[maxn][2];
bool canGo[maxn][2][2];
pair<int, int> intervals[maxn][2];

void calcGraph() {
    rep(i, 0, n) bc += arr[i];
    bc /= n;
    DC << "Barycentre " << bc << eol;
    rep(i, 0, n - 1) {
        ld l = (bc - (i ? deviance[i - 1][0] : 0)) * (n - i);
        ld m = (bc - (i ? deviance[i - 1][0] : 0)) * (n - i);
        ld r = (bc + (i ? deviance[i - 1][1] : 0)) * (n - i);
        l -= (i ? arr[intervals[i - 1][0].second] : arr[n - 1]);
        m -= (i ? arr[intervals[i - 1][0].first] : arr[0]);
        r -= (i ? arr[intervals[i - 1][1].first] : arr[0]);
        l /= (n - i - 1), l -= bc;
        m /= (n - i - 1), m -= bc;
        r /= (n - i - 1), r -= bc;
        DC << " At level " << i << "  " << l << ' ' << m << ' ' << r << eol;
        if(abs(m) <= eps) {
            intervals[i][0] = intervals[i][1] = (i ? intervals[i - 1][0] : make_pair(0, n - 1));
            intervals[i][0].first++, intervals[i][1].first++;
            rep(ii, 0, 2) rep(iii, 0, 2) canGo[i][ii][iii] = true;
        }
        else if(m > 0) {
            canGo[i][0][0] = canGo[i][0][1] = canGo[i][1][1] = true;
            intervals[i][0] = intervals[i][1] = (i ? intervals[i - 1][0] : make_pair(0, n - 1));
            intervals[i][0].second--;
            intervals[i][1].first++;
            deviance[i][0] = -l;
            deviance[i][1] = m;
        }
        else {
            canGo[i][0][0] = canGo[i][1][0] = canGo[i][1][1] = true;
            intervals[i][0] = intervals[i][1] = (i ? intervals[i - 1][1] : make_pair(0, n - 1));
            intervals[i][0].second--;
            intervals[i][1].first++;
            deviance[i][0] = -m;
            deviance[i][1] = r;
        }
        DEBUG {
            DC << "  CanGo ";
            rep(ii, 0, 2) rep(iii, 0, 2) DC << canGo[i][ii][iii] << ' '; DC << eol;
            DC << "  Intervals: (" << intervals[i][0].first << ' ' << intervals[i][0].second << ") (" << intervals[i][1].first << ' ' << intervals[i][1].second << ")" << eol;
            DC << "  Deviance: " << deviance[i][0] << ' ' << deviance[i][1] << eol;
        }
    }
}

void input() {
    scanf("%d", &n);
    rep(i, 0, n) scanf("%lld", arr + i);
}

bool remIsLeft[maxn];
ld maxLeft;

void maxDevLeft(ld maxRight, int start, bool skip) {
    DC << "Going down with max = " << maxRight << " starting from " << start << ": ";
    bool isLeft = (skip ? remIsLeft[start - 1] : false);
    ld ans = 0;
    rep(i, start, n - 1) {
        DC << " " << i << isLeft << "(" << ans << ") ";
        if(canGo[i][(int)!isLeft][1] && deviance[i][1] - maxRight <= eps) isLeft = false;
        else isLeft = true;
        if(isLeft) maxLeft = max(maxLeft, deviance[i][(int)!isLeft]);
        if(isLeft == remIsLeft[i] && skip) { DC << " skip " << eol; break; }
        remIsLeft[i] = isLeft;
    }
    DC << isLeft << "(" << ans << ") " << eol;
}

int main() {
    input();
    calcGraph();
    priority_queue<pair<ld, int>> Q;
    rep(i, 0, n - 1) Q.emplace(deviance[i][1], i + 1);
    maxDevLeft(Q.top().first, 0, 0);
    ld ans = maxLeft + Q.top().first;
    Q.pop();
    while(!Q.empty()) maxDevLeft(Q.top().first, Q.top().second, 1), ans = min(ans, Q.top().first + maxLeft), Q.pop();
    maxDevLeft(0, 0, 0);
    ans = min(ans, maxLeft);
    
    printf("%Lf", ans);
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 1
Accepted
time: 0ms
memory: 8148kb

input:

2
925278587 966813970

output:

20767691.500000

result:

ok found '20767691.500000000', expected '20767691.500000000', error '0.000000000'

Test #2:

score: 0
Wrong Answer
time: 0ms
memory: 8148kb

input:

20
7902238 121690240 160345001 255257832 269315023 288280211 296247186 353929891 494812700 530994847 567379029 567478415 612943598 644028258 654380821 696407711 708542915 738196686 743020754 760907139

output:

21209675.250000

result:

wrong answer 1st numbers differ - expected: '52991294.1666667', found: '21209675.2500000', error = '0.5997517'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%