Submission #849293

#TimeUsernameProblemLanguageResultExecution timeMemory
849293mickey080929Toilets (JOI16_toilets)C++17
100 / 100
19 ms8648 KiB
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") using namespace std; typedef long long ll; ll N, M; vector<pair<string,ll>> v; int main() { ios_base :: sync_with_stdio(false); cin.tie(NULL); cin >> N >> M; ll male = 0; for (ll i=0; i<M; i++) { string s; ll rep; cin >> s >> rep; male += count(s.begin(), s.end(), 'M') * rep; reverse(s.begin(), s.end()); v.emplace_back(s, rep); } if (male > N) { cout << "-1"; return 0; } reverse(v.begin(), v.end()); M = (ll) v.size(); ll val = 0; ll ans = 0; for (ll i=0; i<M; i++) { auto &[s, rep] = v[i]; ll sum = 2 * count(s.begin(), s.end(), 'M') - (ll) s.size(); for (ll j=0; j<s.size(); j++) { if (s[j] == 'M') val ++; else val --; ans = max(ans, val - 1); ans = max(ans, (val + sum*(rep-1)) - 1); } val += sum * (rep-1); } cout << ans; return 0; }

Compilation message (stderr)

toilets.cpp: In function 'int main()':
toilets.cpp:36:23: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         for (ll j=0; j<s.size(); j++) {
      |                      ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...