Submission #157042

#TimeUsernameProblemLanguageResultExecution timeMemory
157042maruiiToilets (JOI16_toilets)C++14
36 / 100
5 ms580 KiB
#include <bits/stdc++.h> using namespace std; char S[200005]; int main() { ios_base::sync_with_stdio(0), cin.tie(0); long long N; int M; cin >> N >> M; long long y = 0, mny = 0; for (int i = 0; i < M; ++i) { int K; cin >> S + 1 >> K; long long sum = 0, mnSum = 0; for (int i = 1, t = 0; S[i]; ++i) { t++; if (S[i] != S[i + 1]) { sum += S[i] == 'M' ? t : -t; mnSum = min(mnSum, sum); t = 0; } } mny = min({mny, y + sum * (K - 1) + mnSum, y + mnSum}); y += K * sum; } if (y > 0) printf("-1"); else printf("%lld", max(0ll, y -mny - 1)); return 0; }

Compilation message (stderr)

toilets.cpp: In function 'int main()':
toilets.cpp:12:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   cin >> S + 1 >> K;
          ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...