QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#358756#407. Toiletsstevo0 1ms3632kbC++20863b2024-03-19 23:39:192024-03-19 23:39:19

Judging History

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

  • [2024-03-19 23:39:19]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:3632kb
  • [2024-03-19 23:39:19]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define st first
#define nd second
#define pb push_back
typedef long long ll;
const int N = 2e5+3;
ll suf[N];
vector<pair<string, ll>> parts;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll n, mc=0;
	ll m, x, out=0;
	cin >> n >> m;
	for(int i=0; i<m; i++){
		string s;
		cin >> s >> x;
		parts.pb({s, x});
	}
	ll lst=0;
	for(int i=m-1; i>=0; i--){
		int ln=parts[i].st.size();
		ll tmpMc=0, mn=0;
		suf[ln]=lst;
		for(int j=ln-1; j>=0; j--){
			suf[j]=suf[j+1];
			if(parts[i].st[j]=='M'){
				tmpMc++;
				suf[j]--;
			}else suf[j]++;
			mn=min(mn, suf[j]);
		}
		tmpMc*=parts[i].nd;
		mn*=parts[i].nd;
		lst=suf[0]*x;
		mc+=tmpMc;
		out=min(out, mn);
	}
	if(mc>n){
		cout << -1 << '\n';
		return 0;
	}
	out*=(-1);
	out--;
	cout << out << '\n';
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 14
Accepted
time: 0ms
memory: 3632kb

input:

10
1
FMFFFFFFMFFFMMMMMFMM 1

output:

5

result:

ok single line: '5'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3620kb

input:

10
1
FFMFMMFFFFMMMFMMMMFF 1

output:

3

result:

ok single line: '3'

Test #3:

score: -14
Wrong Answer
time: 0ms
memory: 3532kb

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%