Submission #693331

#TimeUsernameProblemLanguageResultExecution timeMemory
693331rainboyToilets (JOI16_toilets)C11
36 / 100
21 ms1800 KiB
#include <stdio.h>
#include <string.h>

#define N	200000

long long max(long long a, long long b){ return a > b ? a : b; }

int main() {
	int m;
	long long sum_, suf_;

	scanf("%*d%d", &m);
	sum_ = 0, suf_ = 0;
	while (m--) {
		static char cc[N + 1];
		int n, i;
		long long k, sum, suf;

		scanf("%s%lld", cc, &k), n = strlen(cc);
		sum = suf = 0;
		for (i = 0; i < n; i++) {
			sum += cc[i] == 'M' ? 1 : -1;
			if ((suf += cc[i] == 'M' ? 1 : -1) < 0)
				suf = 0;
		}
		sum_ += sum * k, suf_ = max(suf + sum * k, max(sum * (k - 1), 0) + suf);
	}
	printf("%lld\n", sum_ > 0 ? -1 : (suf_ == 0 ? 0 : suf_ - 1));
	return 0;
}

Compilation message (stderr)

toilets.c: In function 'main':
toilets.c:12:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |  scanf("%*d%d", &m);
      |  ^~~~~~~~~~~~~~~~~~
toilets.c:19:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |   scanf("%s%lld", cc, &k), n = strlen(cc);
      |   ^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...