QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#253366#4571. Even SplitLaStataleBlue#WA 0ms3396kbC++202.1kb2023-11-16 22:07:152023-11-16 22:07:15

Judging History

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

  • [2023-11-16 22:07:15]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3396kb
  • [2023-11-16 22:07:15]
  • 提交

answer

#pragma ide diagnostic ignored "misc-no-recursion"

#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;

#define TESTCASE 0

static constexpr int INF = 1e9;
static constexpr int MAXN = 1e5+10;

int n, len;
int v[MAXN];

bool is_min_ok(int cmin) {
    int start = 0;
    for(int i=0; i<n; i++) {
        if(start > v[i])
            return false;
        start = max(start+cmin, v[i]);
    }
    return start <= len;
}

int ans[MAXN];
bool is_max_ok(int cmax, int cmin) {
    int start = 0, end=0;
    for(int i=0; i<n; i++) {
        if(start > v[i] || end < v[i]-cmax)
            return false;
        start = max(start, v[i]-cmax);
        end = min(end, v[i]);
        if(start > end)
            return false;
        ans[i] = start;
        int tmp = start+cmin;
        start += cmin;
        end += cmax;
        start = max(start, max(tmp, v[i]));
        end = max(end, max(tmp, v[i]));
    }
    return start <= len;
}

static void solve([[maybe_unused]] int tc) {
    cin >> len >> n;
    for(int i=0; i<n; i++)
        cin >> v[i];

    int minlen = 1;
    {
        int left=1, right=len+1;
        while(left+1 != right) {
            int m=(left+right)/2;
            if(is_min_ok(m))
                left = m;
            else
                right = m;
        }
        minlen = left;
    }

    int maxlen = 1;
    {
        int left=minlen, right=len+1;
        while(left+1 != right) {
            int m=(left+right)/2;
            if(is_max_ok(m, minlen))
                left = m;
            else
                right = m;
        }
        maxlen = left;
    }
    is_max_ok(maxlen, minlen);

    for(int i=0; i<n-1; i++)
        cout << ans[i] << ' ' << ans[i+1] << '\n';
    cout << ans[n-1] << ' ' << len << '\n';
}

int main() {
    ios::sync_with_stdio(false);

    if (const char *f = getenv("REDIRECT_STDOUT"); f) {
        freopen(f, "w", stdout);
    }

    int T = 1;
#if TESTCASE
    cin >> T;
#endif

    for (int t = 1; t <= T; t++) {
        solve(t);
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3356kb

input:

6 3
1 3 5

output:

0 2
2 4
4 6

result:

ok Minimal imbalance is 0

Test #2:

score: 0
Accepted
time: 0ms
memory: 3396kb

input:

10 2
1 2

output:

0 2
2 10

result:

ok Minimal imbalance is 6

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3388kb

input:

100 10
14 26 29 31 34 42 44 48 49 68

output:

0 14
14 26
26 29
29 32
32 35
35 42
42 45
45 48
48 51
51 100

result:

wrong answer Jury found better solution (j=29 vs p=46)