UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#159132#228. bookbitsstdcheee302ms1356kbC++1.6kb2022-09-21 17:20:522022-09-21 17:20:55

answer

#include <iostream>
using namespace std;

const int maxn = 1e5 + 10;
int n, p, q, x, y;
bool bi[maxn];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> p >> q >> x >> y;
    int nt = 0;
    for (int i = 1; i <= n; i++) {
        char h;
        cin >> h;
        if (h == '+') bi[i] = true;
        else if (h == '-') bi[i] = false;
        if (bi[i]) nt++;
        else nt--;
    }
    int nc = ((q - p) - nt) / 2;
    if (nc == 0) {
        cout << 0 << endl;
        return 0;
    }
    if (nc > 0) {
        int cnt = 0;
        // - to +
        int i = 1, j = n;   
        while (cnt < nc) {
            if (i > j) break;
            if (cnt < nc && bi[i] == false) {
                bi[i] = true; cnt++;
            }
            if (cnt < nc && bi[j] == false) {
                bi[j] = true; cnt++;
            }
            i++; j--;
        }
        int mm = 0x3f3f3f3f, nm = 0;
        for (int i = 1; i <= n; i++) {
            if (bi[i]) nm++;
            else nm--;
            mm = min(mm, nm);
        }
        if (mm >= 0) cout << nc * x << endl;
        else cout << nc * x - (p + mm) * y << endl;
    }
    else {
        // + to -
        nc = -nc;
        int mm = 0x3f3f3f3f, nm = 0;
        for (int i = 1; i <= n; i++) {
            if (bi[i]) nm++;
            else nm--;
            mm = min(mm, nm);
        }
        // cout << nc << endl;
        if (mm >= 0) cout << nc * x << endl;
        else cout << nc * x - (p + mm) * y << endl;
        // cout << nc * x << endl;
    }
    return 0;
}

Details

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 0ms
memory: 1260kb

input:

100 2 28 9426 9827
----+--+-++++-+++--+---+++------+---------++----+-++++-+--+++-++++++-+-+--+++--++...

output:

179094

result:

ok single line: '179094'

Test #2:

score: 10
Accepted
time: 0ms
memory: 1256kb

input:

100 6 68 8136 6688
+++-+---+----+--+-++--+---++++++--+-++-++--+--++--+-++---+++-+++---++++-+++-+++++...

output:

219672

result:

ok single line: '219672'

Test #3:

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

input:

100 4 0 7368 5364
-+-++---+--+-+-+-++++++++-+-++++--+-+---++---++--+++----+--+-----------+--+--+++--...

output:

48924

result:

wrong answer 1st lines differ - expected: '36840', found: '48924'

Test #4:

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

input:

1000 454 0 10 10000000
--+++++-+---++-++-+-++++-+--+---++++++++-+-++-+-+-+--+++--+----+--++++-++---+...

output:

-5030554

result:

wrong answer 1st lines differ - expected: '2150', found: '-5030554'

Test #5:

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

input:

1000 376 1144 440675445 812725011
++++-+------++---++---+--+++---++++--++--+-++++-+---++++-+++-+-+--...

output:

-270629752

result:

wrong answer 1st lines differ - expected: '158643160200', found: '-270629752'

Test #6:

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

input:

1000 276 18 938498793 701159019
-+++---+++-+---+++---+-+----+++-+-+-++---+--+++++-+---+-++-+----++++...

output:

1513421668

result:

wrong answer 1st lines differ - expected: '95726876886', found: '1513421668'

Test #7:

score: 10
Accepted
time: 0ms
memory: 1356kb

input:

100000 67360 94034 10 10000000
---+++-++-+++---+-+--+-+------+-+---+----+----+-----+-+--+----+++-+--...

output:

131900

result:

ok single line: '131900'

Test #8:

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

input:

100000 57247 91 752278539 881719015
-+++++--+--++---+-----++-+-+++++-+-+--+-----++--+++++-+--+-+++-+...

output:

-2079635734

result:

wrong answer 1st lines differ - expected: '21465515831826', found: '-2079635734'

Test #9:

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

input:

1000000 897028 186010 944612613 866641998
+---+-++++--+---+---+----++--+-+---++---+-+++++++--+++-+--...

output:

-2138691192

result:

wrong answer 1st lines differ - expected: '335957143489128', found: '-2138691192'

Test #10:

score: 0
Wrong Answer
time: 2ms
memory: 1356kb

input:

1000000 524180 1009530 659936979 574325878
++---++--+-++-+---+---+-++--+-++--+----++---+-++-+-+-++-+...

output:

-842105010

result:

wrong answer 1st lines differ - expected: '159568801900326', found: '-842105010'