QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#175370 | #7175. Mixed Messages | zhaohaikun | AC ✓ | 4ms | 4840kb | C++14 | 1.9kb | 2023-09-10 17:42:18 | 2023-09-10 17:42:18 |
Judging History
answer
#include <bits/stdc++.h>
#define SZ(x) (int) x.size() - 1
#define all(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define DF(i, x, y) for (int i = (x); i >= (y); i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> inline void chkmax(T& x, T y) { x = max(x, y); }
template <typename T> inline void chkmin(T& x, T y) { x = min(x, y); }
template <typename T> inline void read(T &x) {
x = 0; int f = 1; char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
x *= f;
}
// const int N = 1e5 + 10;
// int ans = 1e9;
// vector <int> tt[1010];
// void work(vector <int> v) {
// // reverse(all(v));
// int sum = 0;
// for (int i: v) sum += i - 1;
// F(i, 0, SZ(v))
// F(j, i + 1, SZ(v))
// sum += (v[i] < v[j]);
// for (int i: v) cout << i << " "; cout << " -> " << sum << endl;
// chkmin(ans, sum);
// }
// string ss = " spbsu";
int lst[1010], s1[100010], s2[100010], ans = 1e9;
signed main() {
int n; string st; cin >> n >> st;
st = ' ' + st;
s1[0] = 1e9;
F(i, 1, n) {
lst[st[i]] = i;
if (st[i] == 'p' && lst['s']) s1[i] = i - lst['s'] - 1;
else s1[i] = s1[i - 1] + 2;
}
s2[n + 1] = 1e9;
ms(lst, 0);
DF(i, n, 1) {
lst[st[i]] = i;
if (st[i] == 's' && lst['u']) s2[i] = lst['u'] - i - 1;
else s2[i] = s2[i + 1] + 2;
}
F(i, 1, n) {
if (st[i] == 'b') {
chkmin(ans, s1[i - 1] + s2[i + 1]);
// cout << s1[i - 1] << " " << s2[i + 1] << endl;
}
}
// ms(lst, -0x3f);
// F(i, 1, n) {
// // lst[st[i]] = i;
// tt[st[i]].push_back(i);
// if (tt['s'].size() > 1 && tt['p'].size() && tt['b'].size() && tt['u'].size())
// work(vector <int> {i - tt['s'][1], i - tt['p'][0], i - tt['b'][0], i - tt['s'][0], i - tt['u'][0]});
// }
cout << ans;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3616kb
input:
6 spbssu
output:
1
result:
ok answer is '1'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3652kb
input:
15 spongebaseurban
output:
11
result:
ok answer is '11'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
5 spbsu
output:
0
result:
ok answer is '0'
Test #4:
score: 0
Accepted
time: 1ms
memory: 3616kb
input:
6 sppbsu
output:
1
result:
ok answer is '1'
Test #5:
score: 0
Accepted
time: 1ms
memory: 3844kb
input:
13 spbpbsaaaaaau
output:
8
result:
ok answer is '8'
Test #6:
score: 0
Accepted
time: 1ms
memory: 3812kb
input:
100 supsuuuupusbsubsssbpbuubsppppspsusupbuusbuspupuubuspppusubsupbubusbsbsppbuspuspbbusppuppubuubbusbups
output:
4
result:
ok answer is '4'
Test #7:
score: 0
Accepted
time: 1ms
memory: 3624kb
input:
100 nmpnzouzoosynvhsqljejmgwwgmmuaptmazvneojjgapiizxdengrritcqhppnkjxtqsbsvxsuypgbvatxbzmkpcpnizdsmhdzkt
output:
61
result:
ok answer is '61'
Test #8:
score: 0
Accepted
time: 2ms
memory: 4600kb
input:
100000 supsuuuupupbsubsssbpbuubsppppspsusupbuusbuspupuubuspppusubsuububusbsssppbsspuspbbusppuppubuubbusbupspbsusbsuusussssbusubuupppspppusupbspbsbspubbpsuppusbbubuuubpbbubuubbuspbubpbpsbbusubussbsbubbussspbspbubbupsssuusbbssuspbssupusbpppusssppbpsspbppupsssuupbpupussupbsbuubupppubsspsubuubsbubbppuus...
output:
0
result:
ok answer is '0'
Test #9:
score: 0
Accepted
time: 0ms
memory: 4540kb
input:
100000 nmpnzouzoozynvhsqljejmgwwgmmuaptmazvneojjgapiizxdengrritcqhpcnkjxtqsjtvxsbypgbvatxbzmkpcpnizdsmhdzktphjryltupnkahdlbudksxcukgdkexxdxrtypwqttcpjspnucumswliqciutgdaztpvhbutoscnvscylauhrhchwwstonaghwlmnnrdvdbrxafacihdhstibpqyaeckfqcmeetynurqoyaxakcuoyqwuiztkzxeyqcrjqnixfucpkzljhkquwvijhnzyfxiixn...
output:
5
result:
ok answer is '5'
Test #10:
score: 0
Accepted
time: 3ms
memory: 4532kb
input:
100000 sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...
output:
0
result:
ok answer is '0'
Test #11:
score: 0
Accepted
time: 3ms
memory: 4604kb
input:
100000 spppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp...
output:
99995
result:
ok answer is '99995'
Test #12:
score: 0
Accepted
time: 3ms
memory: 4600kb
input:
100000 spbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb...
output:
199990
result:
ok answer is '199990'
Test #13:
score: 0
Accepted
time: 3ms
memory: 4840kb
input:
100000 spbssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...
output:
99995
result:
ok answer is '99995'
Test #14:
score: 0
Accepted
time: 1ms
memory: 4600kb
input:
100000 spbsuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu...
output:
0
result:
ok answer is '0'
Test #15:
score: 0
Accepted
time: 0ms
memory: 4604kb
input:
100000 sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...
output:
79996
result:
ok answer is '79996'
Test #16:
score: 0
Accepted
time: 3ms
memory: 4596kb
input:
100000 spspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspsps...
output:
6
result:
ok answer is '6'
Test #17:
score: 0
Accepted
time: 0ms
memory: 4608kb
input:
100000 spbsuspbsuspbsuspbsuspbsuspbsuspbsuspbsuspbsuspbsuspbsuspbsuspbsuspbsuspbsuspbsuspbsuspbsuspbsuspbsuspbsuspbsuspbsuspbsuspbsuspbsuspbsuspbsuspbsuspbsuspbsuspbsuspbsuspbsuspbsuspbsuspbsuspbsuspbsuspbsuspbsuspbsuspbsuspbsuspbsuspbsuspbsuspbsuspbsuspbsuspbsuspbsuspbsuspbsuspbsuspbsuspbsuspbsuspb...
output:
0
result:
ok answer is '0'
Test #18:
score: 0
Accepted
time: 0ms
memory: 4540kb
input:
100000 spbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbspbsp...
output:
2
result:
ok answer is '2'
Test #19:
score: 0
Accepted
time: 4ms
memory: 4832kb
input:
100000 aausuabubupppauppuaupapaapaaaspbusssbapuuupapbusbpsauppsuppbapuassububbsssupappsbaauauauausubusppsbbsppsasupbusaauaaasbasuubusaaupupbuapsasaabsspaaasabbbpaappsuspbpappapssbsupupbusuuabbsuupusupsbabbbaauspauuasbspbubauupsuusspusupppbbbbuupbusssussupbbssaauubuusbsubabubssuapuspbabpauuaaaaaaasbs...
output:
0
result:
ok answer is '0'
Test #20:
score: 0
Accepted
time: 4ms
memory: 4540kb
input:
100000 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
0
result:
ok answer is '0'
Extra Test:
score: 0
Extra Test Passed