Submission #381209

#TimeUsernameProblemLanguageResultExecution timeMemory
381209patrikpavic2Toilets (JOI16_toilets)C++17
100 / 100
26 ms1388 KiB
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; const int N = 2e5 + 500; ll n, P, S, cF; int m, k; char s[N]; int main(){ scanf("%lld%d", &n, &m); for(;m--;){ ll PP = 0, SS = 0, cFF = 0, kol; scanf("%s %lld", s, &kol); k = strlen(s); for(int i = 0;i < k;i++){ SS += (s[i] == 'F' ? -1 : 1); cFF += (s[i] == 'F'); PP = min(PP, SS); } cF += cFF * kol; P = min(P, S + PP + min(0LL, (kol - 1) * SS)); S += SS * kol; } if(cF < n) printf("-1\n"); else printf("%lld\n", max(0LL, (2LL * n - 2LL * cF - 1) - P)); return 0; }

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]
   16 |  scanf("%lld%d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~~~
toilets.cpp:19:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   19 |   scanf("%s %lld", s, &kol); k = strlen(s);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...