#include<iostream>
#include<vector>
#include<algorithm>
#define ep emplace
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const int inf=1e9+7;
const ll INF=1e18+7;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
ll n;
cin>>n;
int m;
cin>>m;
for(int tc=0;tc<m;tc++)
{
string s;
int k;
cin>>s>>k;
ll mc=0;
int sn=s.size();
for(int i=0;i<sn;i++)
if(s[i]=='M')
mc++;
if(mc>n)
return cout<<-1<<endl,0;
ll cc=0;
ll ans=0;
for(int i=0;i<sn;i++)
if(s[i]=='M')
ans+=max(0ll,i-(n-mc+cc++)*2-1);
cout<<ans<<endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |