QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#359960 | #407. Toilets | Arapak2 | 0 | 1ms | 3776kb | C++14 | 1.5kb | 2024-03-21 06:43:08 | 2024-03-21 06:43:09 |
answer
// Author: Kajetan Ramsza
#include "bits/stdc++.h"
using namespace std;
#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename F, typename S> ostream& operator<<(ostream& os, const pair<F, S> &p) { return os<<"("<<p.first<<", "<<p.second<<")"; }
template<typename T> ostream &operator<<(ostream & os, const vector<T> &v) { os << "{"; typename vector< T > :: const_iterator it;
for( it = v.begin(); it != v.end(); it++ ) { if( it != v.begin() ) os << ", "; os << *it; } return os << "}"; }
void dbg_out() { cerr<<'\n'; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr<<' '<<H; dbg_out(T...); }
#ifdef DEBUG
#define dbg(...) cerr<<"(" << #__VA_ARGS__ <<"):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif
ll n;
int m;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>n>>m;
ll sum = 0;
ll maxi = 0;
ll ind = 0;
rep(o,0,m) {
string s; ll k;
cin>>s>>k;
ll curr = 0;
rep(i,0,sz(s)) {
curr += s[i] == 'F' ? +1 : -1;
// if((ind + ll(i)) & 1)
maxi = max(maxi, sum + curr);
}
sum += curr * (k-1);
ind += ll(sz(s)) * (k-1);
rep(i,0,sz(s)) {
sum += s[i] == 'F' ? +1 : -1;
// if((ind + ll(i)) & 1)
maxi = max(maxi, sum);
}
ind += ll(sz(s));
}
dbg(sum, maxi);
if(sum < 0) cout<<-1<<'\n';
else cout<<maxi - sum - 1<<'\n';
// else cout<<maxi - sum<<'\n';
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 14
Accepted
time: 1ms
memory: 3516kb
input:
10 1 FMFFFFFFMFFFMMMMMFMM 1
output:
5
result:
ok single line: '5'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3572kb
input:
10 1 FFMFMMFFFFMMMFMMMMFF 1
output:
3
result:
ok single line: '3'
Test #3:
score: -14
Wrong Answer
time: 0ms
memory: 3776kb
input:
10 1 MFMMFFFMMFFMMMMFFFFF 1
output:
-1
result:
wrong answer 1st lines differ - expected: '0', found: '-1'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%