QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#136372 | #78. Eggfruit Cake | Redex89 | AC ✓ | 7ms | 6580kb | C++23 | 2.2kb | 2023-08-08 07:10:46 | 2023-08-08 07:10:49 |
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;
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]);
}
}
if(sz(s) / 2 == x && flag)
cout<<ans - (x - 1)<<ENDL;
else
cout<<ans<<ENDL;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3464kb
input:
PEPEP 2
output:
6
result:
ok single line: '6'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3520kb
input:
PPPPPPPPPPPPPPPPPPPP 10
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3500kb
input:
EEEEEEEEEEEEEEEEEEEEE 11
output:
231
result:
ok single line: '231'
Test #4:
score: 0
Accepted
time: 1ms
memory: 3468kb
input:
PPPPPPPPPPPPPPPPPPPPPP 12
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3500kb
input:
PPEEPPEPEEPPPEPEEEPEEEP 13
output:
281
result:
ok single line: '281'
Test #6:
score: 0
Accepted
time: 1ms
memory: 3488kb
input:
PPPPPPPPPPPPPPPPPPPPPPPP 14
output:
0
result:
ok single line: '0'
Test #7:
score: 0
Accepted
time: 1ms
memory: 3496kb
input:
PEEEPEEPEPPPPEEEPPPEEPPEP 15
output:
351
result:
ok single line: '351'
Test #8:
score: 0
Accepted
time: 1ms
memory: 3524kb
input:
PEPPPEPPEEPEPPPPPEPPEPPPPE 16
output:
377
result:
ok single line: '377'
Test #9:
score: 0
Accepted
time: 5ms
memory: 6252kb
input:
PPEPPPPPPPPPPEEPPEPPPPPPEPEPPPEPPPEEPPEPEPPPEEPPPPPEPPPPPEEPEPPPPEEEPPPEPPPPEEEPEPEPPEEPPEPEEPPPEPPPPPPPPEPPEPPPPPEEPPEPEEPPPPPEPPPPEPEPPPPEPEPPPPEPEPPPPPPPEPPEEPPPEPPEPEEPPEEEEEEPEPPPEPEPPEEEEEPEPPPEEEPPEPEPPPEPPPPEEPEEPPPPEPPEPPPPPPPPPPPPEPPPEPPPPPPEPPEPPEPPPPPPPEPPEPPPEPEEPPEPEPPPPEPPPEPEEEPPPPPP...
output:
9797610
result:
ok single line: '9797610'
Test #10:
score: 0
Accepted
time: 4ms
memory: 5728kb
input:
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE...
output:
9999900000
result:
ok single line: '9999900000'
Test #11:
score: 0
Accepted
time: 6ms
memory: 6168kb
input:
EPPPPPEEPPPPPEPPEEPPEPPPPEEPPPPPPPPPPPPPPPEPPPPPPPEPPPPEPPPEEPPPPEPPEPEPEPPEPPEPPPPPPPPPPPEPPPPPPPPPEPEEPPPPPPEPPEPPPPPPPPPEPEPEPPPPPPPPPPPPPEPEEPEPEPPEPPEEPPPEEEPPEPPPPEPEEPPPPPPPPPPPEPPPPPPPEPPPPPPEPPPEPPPPEPPPPPPEPPEEEPEPPEPPPPPPPPPEEPEPPPEPPPPEEEEEPPPPPEPPEPPPPPPPPEPPEPEPPEPPPPPPEPPPPPPPEPPEPPPP...
output:
6285741
result:
ok single line: '6285741'
Test #12:
score: 0
Accepted
time: 1ms
memory: 3460kb
input:
EPE 1
output:
2
result:
ok single line: '2'
Test #13:
score: 0
Accepted
time: 5ms
memory: 5644kb
input:
EEEPEEEEEPEEEEEPEEEPPEEEEEEEEPEEEEEEEEPEPEEPEEEEEEPPEEEEEEEPEEEEEEEEEPEEPEEEEPEEPEEPPEPEEEEPEEEPEEEEEEEEEEEEEEEEEPEEEPEEEEEEEPEPEPEPEEEEEEPEEEEEEEEEEEEEEEEEEEPPEEEEEEEEEEEEEEEEEEEEEPEPEEPEEEEPEEEEEEEEEEEEEPEEEEEEEEEEEEEEPPEEEPEPEEEPEEEEPEEEPEEPEEEEEEEEEEEEPPEEEEEEEEEEEEEEEEEEPEPEEEEEEEEEEEPEPEEEPEPE...
output:
6859883263
result:
ok single line: '6859883263'
Test #14:
score: 0
Accepted
time: 4ms
memory: 6440kb
input:
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPEPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP...
output:
2441378840
result:
ok single line: '2441378840'
Test #15:
score: 0
Accepted
time: 5ms
memory: 6516kb
input:
PPPPPPPPPPPPPPPPPPPPPPPPPEPPPPPPPPPPEPEPPPPPPPPPPPEPEPPPPPPPPPPPPPPPPPPPPPPEPPPPPPPPPPPPPPEPPPPPPPPPPEEPPPPEPPPPPPPPPPPPPPPPPEPPPPPPPPPPPPPPPPPPEPPPPPPPPPPPPPPPEEPPPPPPPPPPPPPEPPPPEEPPPEPPPPPPPPPPPPPPPPPPPEPPPEPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPEPEPPPEPPPPPPPEPPPPPPPPPPPPPPPEPPPPPPPPPPPPEPPPPPPPPPEPPP...
output:
7835156010
result:
ok single line: '7835156010'
Test #16:
score: 0
Accepted
time: 7ms
memory: 5892kb
input:
EEPPEEEEPPEPPEPPPPPEPPEEEEEEEPEEEPEEEPPEPEEPEEPEEEPEEEPEPPEPEEEEPEEEPEPPPEPPPPEPEPPPEPEPEPPPEEEEPEEPPPPPEPEPEPEPEEPPEEPPEPEPPPEEPPEPPPPEPEPEEEPPPEPPEEPEPEPEEEEEEEEPPEPPPPPEEEEEEPEEPEEPPEEPPEEEEEEEEEPPPPPPEEEPEPEPEPEEEEEEPPPEEPEEPPEPPEPEEEPPEEPEEEEEEPPEPEEEPEPPPEPPEPPEEEEEPPEEPPEPEPEEPEPPEEEPEEPPEPEP...
output:
5330324036
result:
ok single line: '5330324036'
Test #17:
score: 0
Accepted
time: 4ms
memory: 5680kb
input:
EEEEEEEEEEPEEEEEEEEEPEEEEEEPEPEEEEEEEEEEEEPEEEEEEEEEEPEEEEEEEEEEEEEEEEEEEEEPEEEEEEEEEEEEEEEEEEEEEEEPEEEEPEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEPEEEEEEEEEEEEEEEEEEEEEEEPEEEEEEEEEEEEPEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEPEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE...
output:
9062395582
result:
ok single line: '9062395582'
Test #18:
score: 0
Accepted
time: 2ms
memory: 6396kb
input:
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPEPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP...
output:
2481607
result:
ok single line: '2481607'
Test #19:
score: 0
Accepted
time: 4ms
memory: 5716kb
input:
EEEEEEPPEEEEEEEEEEEEEEEEEEEEPEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEPEEEPPEEEEEEEEEEEEEEEEEEEEEEEEEEEPPEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEPEEEEEEEEEEEEEEEEEEEEPEEEEEEEEEEEPEEPEEEEEEEEEEEPEEEEEEEEEEEEEEEEEEEEEEEEEPEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEPE...
output:
8294039
result:
ok single line: '8294039'
Test #20:
score: 0
Accepted
time: 2ms
memory: 6504kb
input:
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP...
output:
8086241960
result:
ok single line: '8086241960'
Test #21:
score: 0
Accepted
time: 2ms
memory: 5588kb
input:
EEEEEEEEEEPEEEEPEEEEPEEEEEEPEPEEEEEEEEEEEEPPEEEEEEEEEPEEEEEEEEEEEEEEEEEEEEEPEPEEEEEPEEEEEEEEEEEEEEEPEEEEPEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEPEEEEEEEEEEEEEEEEEEEEEEEPEEEEEEEEEEEEPEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEPEEEEEEEEEEEPEEEEEEEEEEEEEEEEEEEEEPEEEEEPEEPEEEEEEEEE...
output:
8097991676
result:
ok single line: '8097991676'
Test #22:
score: 0
Accepted
time: 2ms
memory: 3584kb
input:
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP...
output:
0
result:
ok single line: '0'
Test #23:
score: 0
Accepted
time: 1ms
memory: 3536kb
input:
PPPP 1
output:
0
result:
ok single line: '0'
Test #24:
score: 0
Accepted
time: 4ms
memory: 5752kb
input:
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE...
output:
3579500000
result:
ok single line: '3579500000'
Test #25:
score: 0
Accepted
time: 1ms
memory: 3460kb
input:
EPEP 2
output:
6
result:
ok single line: '6'
Test #26:
score: 0
Accepted
time: 1ms
memory: 3520kb
input:
EEE 1
output:
3
result:
ok single line: '3'
Test #27:
score: 0
Accepted
time: 0ms
memory: 3456kb
input:
PPP 1
output:
0
result:
ok single line: '0'
Test #28:
score: 0
Accepted
time: 4ms
memory: 6440kb
input:
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP...
output:
7000050000
result:
ok single line: '7000050000'
Test #29:
score: 0
Accepted
time: 4ms
memory: 6404kb
input:
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP...
output:
6500050000
result:
ok single line: '6500050000'
Test #30:
score: 0
Accepted
time: 4ms
memory: 6580kb
input:
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP...
output:
5000050000
result:
ok single line: '5000050000'