이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 101010;
ll n, m, cnt[N]; string s[N];
int main() {
cin.tie(0); ios_base::sync_with_stdio(0);
cin >> n >> m;
ll var = 0;
for (int i = 0; i < m; i++) {
cin >> s[i] >> cnt[i];
reverse(s[i].begin(), s[i].end());
int v = 0;
for (int j = 0; j < s[i].size(); j++) {
if (s[i][j] == 'M')
++v;
else
--v;
}
var += 1ll * v * cnt[i];
}
if (var > 0)
return !(cout << -1);
ll T = 0, V = 0;
for (int i = m - 1; i >= 0; i--) {
ll t = 0, v = 0;
for (int j = 0; j < s[i].size(); j++) {
if (s[i][j] == 'M')
++t;
else
--t;
v = max(v, t);
}
if (t >= 0)
V = max(V, T + (cnt[i] - 1) * t + v);
else
V = max(V, T + v);
T += cnt[i] * t;
}
cout << max(0ll, V - 1);
}
컴파일 시 표준 에러 (stderr) 메시지
toilets.cpp: In function 'int main()':
toilets.cpp:17:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | for (int j = 0; j < s[i].size(); j++) {
| ~~^~~~~~~~~~~~~
toilets.cpp:31:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for (int j = 0; j < s[i].size(); j++) {
| ~~^~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |