QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#358244#407. Toiletsbonkar0 1ms3556kbC++142.1kb2024-03-19 18:24:252024-03-19 18:24:26

Judging History

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

  • [2024-03-19 18:24:26]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:3556kb
  • [2024-03-19 18:24:25]
  • 提交

answer

/* Generated by the powerful Sio Tool
 * You can download the binary file here: https://github.com/Arapak/sio-tool
 * Author:  (Karol Bonat)
 * Time of creation: 2024-03-19 10:29:46
 * Notes: 
**/

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

constexpr int MAXN = 1000006;

int n, M;
int m, f;

int nxt_m[MAXN];
int nxt_f[MAXN];



bool tab[MAXN]; // 1 - female

bool usd[MAXN];

int find(int i, int *nxt){
	if(i > n){
		return i;
	}
	if(usd[i]){
		nxt[i] = find(nxt[i], nxt);
		return nxt[i];
	}
	return i;
}

bool test(int lim){
	int mf = (n/2-m);
	for(int i = 1; i <= n; i++){
		usd[i] = 0;
	}
	int cnt = 0;
	for(int i = 1; i <= n; ){
		cnt -= (usd[i] && !tab[i]);
		if(usd[i]){
			i++;
			continue;
		}
		int j = i+1;
		while(usd[j]){
			cnt-=(!tab[j]);
			j++;
		}
		if(tab[i] && tab[j] && cnt < lim){
			int nm = find(nxt_m[j], nxt_m);
			if(nm <= n){
				cnt++;
				usd[nm] = 1;
				i=j;
				continue;
			}
		}
		if(tab[i] && tab[j]){
			//We failed to joink (probably cnt=lim), try to push it through
			if(mf){
				i=j+1;
				mf--;
				continue;
			}
			else{
				return 0;
			}
		}
		if(!tab[i] && !tab[j]){
			//We automatically joink a fem
			int nf = find(nxt_f[j], nxt_f);
			if(nf <= n){
				usd[nf]=1;
				i=j;
				continue;
			}
			else{
				return 0;
			}
		}
		//We hae male-female, nothing happens
		i=j+1;
	}
	return 1;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> M;
	string s;
	while(M--){
		string t; int k;
		cin >> t >> k;
		while(k--){
			s+=t;
		}
	}
	for(char t : s){
		m+=t=='M';
		f+=t=='F';
	}
	if(m > n){
		cout << "-1\n";
		return 0;
	}
	n*=2;
	for(int i = 1; i <= n; i++){
		tab[i] = s[i-1]=='F';
	}

	int nf = n+1, nm = n+1;
	for(int i = n; i >= 1; i--){
		nxt_f[i] = nf;
		nxt_m[i] = nm;
		if(tab[i]) nf=i;  
		else nm=i;  
	}
	//Motha fucka
	int p = 0, k = n;
	while(p <= k){
		int s = (p+k)/2;
		if(test(s)){
			k=s-1;
		}
		else{
			p=s+1;
		}
	}
	cout << p << '\n';
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3556kb

input:

10
1
FMFFFFFFMFFFMMMMMFMM 1

output:

10

result:

wrong answer 1st lines differ - expected: '5', found: '10'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%