Submission #53853

#TimeUsernameProblemLanguageResultExecution timeMemory
53853aintaToilets (JOI16_toilets)C++17
100 / 100
41 ms5688 KiB
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
long long L;
int n;
char p[201000];
struct point {
	string T;
	int s, M;
	long long K;
}w[101000];
long long ss;
int main() {
	int i, j;
	scanf("%lld%d", &L, &n);
	long long M = 0;
	for (i = 1; i <= n; i++) {
		scanf("%s", p);
		scanf("%lld", &w[i].K);
		w[i].s = w[i].M = 0;
		for (j = 0; p[j]; j++) {
			if (p[j] == 'F')w[i].s++;
			else w[i].s--;
			w[i].M = max(w[i].M, w[i].s);
		}
		M = max(M, max(ss + w[i].M, ss + w[i].s*(w[i].K - 1) + w[i].M));
		ss += w[i].s*w[i].K;
	}
	if (ss < 0) {
		puts("-1");
		return 0;
	}
	if (M < ss + 1)puts("0");
	else printf("%lld\n", M - (ss + 1));
}

Compilation message (stderr)

toilets.cpp: In function 'int main()':
toilets.cpp:16:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%d", &L, &n);
  ~~~~~^~~~~~~~~~~~~~~~~~
toilets.cpp:19:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s", p);
   ~~~~~^~~~~~~~~
toilets.cpp:20:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", &w[i].K);
   ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...