QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#136366 | #78. Eggfruit Cake | Redex89 | WA | 1ms | 3532kb | C++14 | 2.2kb | 2023-08-08 05:13:55 | 2023-08-08 05:13:58 |
Judging History
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;
if(s.find('E') == -1){
cout<<0<<ENDL;
return 0;
}
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]);
}
}
}
cout<<ans<<ENDL;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3528kb
input:
PEPEP 2
output:
6
result:
ok single line: '6'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3496kb
input:
PPPPPPPPPPPPPPPPPPPP 10
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3528kb
input:
EEEEEEEEEEEEEEEEEEEEE 11
output:
231
result:
ok single line: '231'
Test #4:
score: 0
Accepted
time: 1ms
memory: 3488kb
input:
PPPPPPPPPPPPPPPPPPPPPP 12
output:
0
result:
ok single line: '0'
Test #5:
score: -100
Wrong Answer
time: 1ms
memory: 3532kb
input:
PPEEPPEPEEPPPEPEEEPEEEP 13
output:
270
result:
wrong answer 1st lines differ - expected: '281', found: '270'