QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#358162#407. ToiletsAMongus21370 0ms3812kbC++20841b2024-03-19 17:52:002024-03-19 17:52:02

Judging History

你现在查看的是最新测评结果

  • [2024-03-19 17:52:02]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:3812kb
  • [2024-03-19 17:52:00]
  • 提交

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%