QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#358287 | #407. Toilets | AMongus2137 | 0 | 1ms | 3832kb | C++20 | 815b | 2024-03-19 18:47:30 | 2024-03-19 18:47:31 |
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n, m;
int main()
{
ios::sync_with_stdio(0), cin.tie(0);
cin >> n >> m;
ll minn = -1, dif = 0;
for (int c, i = 0; i < m; i++)
{
string s;
cin >> s >> c;
ll subdif = 0, submin = 0;
for (auto z : s)
{
subdif += (z == 'M' ? 1LL : -1LL);
submin = min(submin, subdif);
}
ll totmin = 0;
if (subdif < 0)
{
totmin = subdif * (c - 1);
}
totmin += submin;
minn = min(minn, dif + totmin);
dif += subdif * c;
}
if (dif > 0)
{
cout << "źle1\n";
cout << "-1\n";
return 0;
}
cout << max(0LL, dif - (minn + 1)) << "\n";
}
/*
2 1
FFMF 1
6 1
MFFFMFMMFFFM 1
6 1
FFFMMMMMMFFF 1
6 3
F 3
M 6
F 3
*/
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 14
Accepted
time: 1ms
memory: 3776kb
input:
10 1 FMFFFFFFMFFFMMMMMFMM 1
output:
5
result:
ok single line: '5'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3832kb
input:
10 1 FFMFMMFFFFMMMFMMMMFF 1
output:
3
result:
ok single line: '3'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3524kb
input:
10 1 MFMMFFFMMFFMMMMFFFFF 1
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3520kb
input:
10 1 FMFMFFMFMFMMFFMFMFMM 1
output:
1
result:
ok single line: '1'
Test #5:
score: -14
Wrong Answer
time: 0ms
memory: 3812kb
input:
10 1 MFFFMFMMMMMMMMMFMFFM 1
output:
źle1 -1
result:
wrong answer 1st lines differ - expected: '-1', found: 'źle1'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%