QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#136368#78. Eggfruit CakeRedex89WA 1ms3544kbC++142.3kb2023-08-08 05:30:152023-08-08 05:30:18

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-08 05:30:18]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3544kb
  • [2023-08-08 05:30:15]
  • 提交

answer

#include <bits/stdc++.h>
//Pura gente del coach moy
using namespace std;
#define ENDL '\n'
#define all(x)  x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x)   (int) x.size()
#define FOR(x, b)     for(int x = 0; x <b; x++)
#define FORE(x, a, b) for(int x = a; x <= b; x++)
#define FORR(x, a, b) for(int x = a; x >= b; x--)
#define deb(x)      cerr << #x << " = " << x << '\n';
#define deb2(x, y)  cerr << #x << " = " << x << ", " << #y << " = " << y << '\n';
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
const ll MOD = 1e9+7, INF = 1e18;

int main(){_
    string s;
    int x;
    cin>>s>>x;

    bool flag = 0;

    if(s.find('E') == -1){
        cout<<0<<ENDL;
        return 0;
    }

    if(s.find('P') == -1)
        flag = 1;

    s += s;
    int n = sz(s);
    stack<int> st;
    vi prevE(n, -1), nextE(n, -1);

    vi a(n);
    FOR(i, n)
        a[i] = s[i];

    int cntP = 1;
    FOR(i, n)
        if(a[i] == 80)
            a[i] += cntP, cntP++;

    for(int i=0; i<n; i++){
        while((!st.empty() && a[i] <= a[st.top()])){
            nextE[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }

    while(!st.empty())
        st.pop();

    cntP = 1;
    FOR(i, n)
        if(a[i] != 69)
            a[i] = 80 - cntP, cntP++;

    for(int i = n - 1; i >= 0; i--){
        while((!st.empty() && a[i] <= a[st.top()])){
            prevE[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }

    FOR(i, n / 2){
        nextE[i] -= i;
        // cout<<nextE[i]<<" ";
    }
    // cout<<ENDL;

    FORE(i, n / 2, n - 1){
        prevE[i] = i - prevE[i];
        // cout<<prevE[i]<<" ";
    }
    // cout<<ENDL;

    ll ans = 0;
    FOR(i, n / 2){
        if(s[i] == 'E')
            ans++;
        if(nextE[i] < x){
            ans += (x - nextE[i]);
        }
    }

    FORE(i, n / 2, n - 1){
        if(s[i] == 'P'){
            if(prevE[i] < x){
                // ans += (x - prevE[i]);
                ans++;
            }
        }
    }

    if(sz(s) / 2 == x && flag)
        cout<<ans - (x - 1)<<ENDL;
    else
        cout<<ans<<ENDL;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3532kb

input:

PEPEP
2

output:

6

result:

ok single line: '6'

Test #2:

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

input:

PPPPPPPPPPPPPPPPPPPP
10

output:

0

result:

ok single line: '0'

Test #3:

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

input:

EEEEEEEEEEEEEEEEEEEEE
11

output:

231

result:

ok single line: '231'

Test #4:

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

input:

PPPPPPPPPPPPPPPPPPPPPP
12

output:

0

result:

ok single line: '0'

Test #5:

score: -100
Wrong Answer
time: 1ms
memory: 3544kb

input:

PPEEPPEPEEPPPEPEEEPEEEP
13

output:

270

result:

wrong answer 1st lines differ - expected: '281', found: '270'