Submission #56005

#TimeUsernameProblemLanguageResultExecution timeMemory
56005youngyojunToilets (JOI16_toilets)C++11
100 / 100
44 ms2700 KiB
#include <bits/stdc++.h> #define pb push_back #define eb emplace_back #define sz(V) ((int)(V).size()) #define allv(V) ((V).begin()),((V).end()) #define befv(V) ((V)[(sz(V)-2)]) #define sorv(V) sort(allv(V)) #define revv(V) reverse(allv(V)) #define univ(V) (V).erase(unique(allv(V)),(V).end()) #define clv(V) (V).clear() #define upmin(a,b) (a)=min((a),(b)) #define upmax(a,b) (a)=max((a),(b)) #define INF (0x3f3f3f3f) #define INFLL (0x3f3f3f3f3f3f3f3fll) using namespace std; typedef long long ll; char A[200005]; ll sum, mn; ll M, X; int main() { scanf("%*lld%lld", &M); for(; M--;) { scanf(" %s%lld", A, &X); ll ret = 0, h = 0; for(int i = 0; A[i]; i++) { ret += ('M' == A[i] ? 1 : -1); upmin(h, ret); } upmin(mn, sum + min({h, h + ret*(X-1), ret*X})); sum += ret*X; } mn -= sum; if(0 < sum) puts("-1"); else if(-1 <= mn) puts("0"); else cout << (-mn-1) << endl; return 0; }

Compilation message (stderr)

toilets.cpp: In function 'int main()':
toilets.cpp:24:23: warning: use of assignment suppression and length modifier together in gnu_scanf format [-Wformat=]
  scanf("%*lld%lld", &M);
                       ^
toilets.cpp:24:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%*lld%lld", &M);
  ~~~~~^~~~~~~~~~~~~~~~~
toilets.cpp:26:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf(" %s%lld", A, &X);
   ~~~~~^~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...