QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#136371#78. Eggfruit CakeRedex89WA 1ms3588kbC++232.3kb2023-08-08 07:09:312023-08-08 07:09:35

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 07:09:35]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3588kb
  • [2023-08-08 07:09:31]
  • 提交

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+=x;
        else 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;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3588kb

input:

PEPEP
2

output:

8

result:

wrong answer 1st lines differ - expected: '6', found: '8'