Submission #157043

#TimeUsernameProblemLanguageResultExecution timeMemory
157043maruiiToilets (JOI16_toilets)C++14
100 / 100
30 ms1912 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) { long long K, sum = 0, mnSum = 0; cin >> S + 1 >> K; 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...