Submission #991376

#TimeUsernameProblemLanguageResultExecution timeMemory
991376gmroh06Toilets (JOI16_toilets)C++14
100 / 100
17 ms5656 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; inline void fastio() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.tie(nullptr); } ll n, m, ans, sum; stack<pair<string, ll>> s; int main() { fastio(); cin >> n >> m; while (m--) { string str; ll t; cin >> str >> t; s.emplace(str, t); } while (!s.empty()) { auto [str, k] = s.top(); s.pop(); ll mx = 0, tmp = 0; for (auto it = str.end() - 1; it >= str.begin(); it--) { tmp += *it == 'M' ? 1 : -1; mx = max(mx, tmp); } ans = max({ans, sum + (k - 1) * tmp + mx - 1, sum + mx - 1}); sum += k * tmp; } cout << (sum > 0 ? -1 : ans); return 0; }

Compilation message (stderr)

toilets.cpp: In function 'int main()':
toilets.cpp:29:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   29 |         auto [str, k] = s.top();
      |              ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...