#include <bits/stdc++.h>
using namespace std;
#define fileio() freopen("input.txt","r",stdin); freopen("output.txt","w",stdout)
#define fio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(x) (x).begin(), (x).end()
#define allr(x) x.rbegin(), x.rend()
#define cmprs(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define endl "\n"
#define sp " "
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define rz resize
#define sz(a) (int)(a.size())
#define clr(a) a.clear()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef tuple<int, int, int> tpi;
typedef tuple<ll, ll, ll> tpl;
typedef pair<double, ll> pdl;
typedef pair<double, int> pdi;
const int dx[] = {1,-1,0,0,1,1,-1,-1};
const int dy[] = {0,0,1,-1,1,-1,1,-1};
const ll MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int MAX = 202020; // PLZ CHK!
ll N,M,K;
int usd[MAX];
string S;
vector<int> FI;
int main() {
fio();
cin>>N>>M;
for (int i=0; i<M; i++) {
string t; ll k;
cin>>t>>k;
S+=t;
}
S=' '+S;
for (int i=1; i<=2*N; i++) {
if (S[i]=='F') FI.pb(i);
}
int m=0,f=0;
int ans=0;
for (int i=2*N; i>=1; i--) {
if (S[i]=='M') m++;
else f++;
if (m>=f+2) {
ans=max(ans, m-f-1);
}
}
cout<<(m>f?-1:ans);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
416 KB |
Output is correct |
12 |
Correct |
0 ms |
600 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
416 KB |
Output is correct |
12 |
Correct |
0 ms |
600 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
3 ms |
1580 KB |
Output is correct |
24 |
Correct |
3 ms |
1620 KB |
Output is correct |
25 |
Correct |
3 ms |
1632 KB |
Output is correct |
26 |
Correct |
2 ms |
2140 KB |
Output is correct |
27 |
Correct |
1 ms |
1132 KB |
Output is correct |
28 |
Correct |
3 ms |
1508 KB |
Output is correct |
29 |
Correct |
3 ms |
2140 KB |
Output is correct |
30 |
Correct |
3 ms |
1632 KB |
Output is correct |
31 |
Correct |
3 ms |
1632 KB |
Output is correct |
32 |
Correct |
3 ms |
1636 KB |
Output is correct |
33 |
Correct |
2 ms |
1056 KB |
Output is correct |
34 |
Correct |
2 ms |
2144 KB |
Output is correct |
35 |
Correct |
4 ms |
1632 KB |
Output is correct |
36 |
Correct |
3 ms |
1884 KB |
Output is correct |
37 |
Correct |
2 ms |
2140 KB |
Output is correct |
38 |
Correct |
3 ms |
1448 KB |
Output is correct |
39 |
Correct |
3 ms |
1632 KB |
Output is correct |
40 |
Correct |
3 ms |
2008 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
416 KB |
Output is correct |
12 |
Correct |
0 ms |
600 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
3 ms |
1580 KB |
Output is correct |
24 |
Correct |
3 ms |
1620 KB |
Output is correct |
25 |
Correct |
3 ms |
1632 KB |
Output is correct |
26 |
Correct |
2 ms |
2140 KB |
Output is correct |
27 |
Correct |
1 ms |
1132 KB |
Output is correct |
28 |
Correct |
3 ms |
1508 KB |
Output is correct |
29 |
Correct |
3 ms |
2140 KB |
Output is correct |
30 |
Correct |
3 ms |
1632 KB |
Output is correct |
31 |
Correct |
3 ms |
1632 KB |
Output is correct |
32 |
Correct |
3 ms |
1636 KB |
Output is correct |
33 |
Correct |
2 ms |
1056 KB |
Output is correct |
34 |
Correct |
2 ms |
2144 KB |
Output is correct |
35 |
Correct |
4 ms |
1632 KB |
Output is correct |
36 |
Correct |
3 ms |
1884 KB |
Output is correct |
37 |
Correct |
2 ms |
2140 KB |
Output is correct |
38 |
Correct |
3 ms |
1448 KB |
Output is correct |
39 |
Correct |
3 ms |
1632 KB |
Output is correct |
40 |
Correct |
3 ms |
2008 KB |
Output is correct |
41 |
Runtime error |
14 ms |
3028 KB |
Execution killed with signal 11 |
42 |
Halted |
0 ms |
0 KB |
- |