QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#358162 | #407. Toilets | AMongus2137 | 0 | 0ms | 3812kb | C++20 | 841b | 2024-03-19 17:52:00 | 2024-03-19 17:52:02 |
answer
#include <bits/stdc++.h>
using namespace std;
int n, m;
string S;
vector<long> P;
int main()
{
ios::sync_with_stdio(0), cin.tie(0);
cin >> n >> m;
for (int c, i = 0; i < m; i++)
{
string x;
cin >> x >> c;
for (; c--;)
S.append(x);
}
P.resize(2 * n + 1);
long dif = 0;
long minn = 0;
for (int i = 0; i < 2 * n; i++)
{
dif += S[i] == 'M' ?: -1;
P[i + 1] = P[i] + (S[i] == 'M' ?: -1);
minn = min(minn, P[i + 1]);
}
// for (int i = 0; i < 2 * n; i++)
// {
// cout << P[i + 1] << " ";
// }
// cout << "\n";
// cout << dif << " " << minn << "\n";
if (dif > 0 || P[2 * n] < dif)
{
cout << "-1\n";
return 0;
}
cout << dif - (minn + 1) << "\n";
}
/*
6
1
MFFFMFMMFFFM 1
6
1
FFFMMMMMMFFF 1
6
3
F 3
M 6
F 3
*/
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 14
Accepted
time: 0ms
memory: 3532kb
input:
10 1 FMFFFFFFMFFFMMMMMFMM 1
output:
5
result:
ok single line: '5'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3812kb
input:
10 1 FFMFMMFFFFMMMFMMMMFF 1
output:
3
result:
ok single line: '3'
Test #3:
score: -14
Wrong Answer
time: 0ms
memory: 3536kb
input:
10 1 MFMMFFFMMFFMMMMFFFFF 1
output:
-1
result:
wrong answer 1st lines differ - expected: '0', found: '-1'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%