QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#498940#5210. Lisa's SequencesPorNPtreeWA 5ms30500kbC++172.2kb2024-07-30 21:58:252024-07-30 21:58:26

Judging History

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

  • [2024-07-30 21:58:26]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:30500kb
  • [2024-07-30 21:58:25]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 5;

int a[N];

struct op {
    int v, ud, val, tlen, len;
    op *prev;

    op(int V = 0, int UD = 0, int VAL = 0, int TLEN = 0, int LEN = 0, op *PREV = NULL) {
        v = V, ud = UD, val = VAL, tlen = TLEN, len = LEN, prev = PREV;
    }

    int operator < (op y) {
        if (v != y.v) return v < y.v;
        if (tlen != y.tlen) return tlen < y.tlen;
        if (len != y.len) return len < y.len;
        if (ud != y.ud) return ud < y.ud;
        if (val != y.val) return val < y.val;
        return 0;
    }

    int operator > (op y) {
        return y < *this;
    }

    int operator == (op y) {
        return !(*this < y) && !(*this > y);
    }
};

vector<op> f[N];
int res[N];

signed main() {
    int n, m; scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
    f[1].push_back(op(1, 1, -1, 1, 1));
    f[1].push_back(op(0, 1, 0, 1, 1));
    f[1].push_back(op(0, -1, 0, 1, 1));
    f[1].push_back(op(1, -1, 1, 1, 1));
    for (int i = 2; i <= n; ++i) {
        for (auto &x : f[i - 1]) {
            if (x.ud != -1) f[i].push_back(op(x.v + 1, -1, -1, 1, x.tlen + 1, &x));
            if (x.ud != 1) f[i].push_back(op(x.v + 1, 1, 1, 1, x.tlen + 1, &x));
            int V = (x.val == -1 ? 0 : (!x.val ? a[i - 1] : 1e5)),
                ud = (a[i] == V ? x.ud : (a[i] < V ? -1 : 1)),
                tlen = (a[i] == V ? x.tlen + 1 : 1),
                len = (a[i] == V || ((a[i] > V) ^ (x.ud == -1)) ? x.len + 1 : x.tlen + 1);
            f[i].push_back(op(x.v, ud, 0, tlen, len, &x));
        }
        f[0].clear();
        for (auto x : f[i]) if (x.len < m && (i == n || x.tlen + 1 < m)) f[0].push_back(x);
        f[i] = f[0];
        sort(f[i].begin(), f[i].end());
        f[i].erase(unique(f[i].begin(), f[i].end()), f[i].end());
        while (f[i].back().v != f[i][0].v) f[i].pop_back();
    }
    op now = *min_element(f[n].begin(), f[n].end());
    printf("%d\n", now.v);
    for (int i = n; i >= 1; --i) {
        res[i] = (now.val == -1 ? 0 : (!now.val ? a[i] : 1e5));
        if (i != 1) now = *(now.prev);
    }
    for (int i = 1; i <= n; ++i) printf("%d%c", res[i], " \n"[i == n]);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 28448kb

input:

5 3
1 2 3 4 5

output:

2
1 2 0 4 0

result:

ok 2

Test #2:

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

input:

6 3
1 1 1 1 1 1

output:

3
1 0 1 0 1 0

result:

ok 3

Test #3:

score: 0
Accepted
time: 3ms
memory: 30488kb

input:

6 4
1 1 4 4 1 1

output:

1
1 1 4 0 1 1

result:

ok 1

Test #4:

score: 0
Accepted
time: 2ms
memory: 28524kb

input:

6 4
4 4 4 2 2 2

output:

2
4 4 0 2 2 0

result:

ok 2

Test #5:

score: 0
Accepted
time: 5ms
memory: 30384kb

input:

6 4
4 4 4 3 4 4

output:

1
4 4 100000 3 4 4

result:

ok 1

Test #6:

score: 0
Accepted
time: 2ms
memory: 30500kb

input:

8 4
2 1 1 3 3 1 1 2

output:

2
2 1 1 3 0 1 1 0

result:

ok 2

Test #7:

score: -100
Wrong Answer
time: 5ms
memory: 30376kb

input:

10 4
1 1 1 2 2 1 1 2 2 1

output:

3
1 1 0 2 2 1 100000 2 2 100000

result:

wrong answer Jury has better solution 2, only 3 found