| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 55433 | Diuven | Toilets (JOI16_toilets) | C++11 | 5 ms | 896 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MX=200010, inf=2e9;
ll n;
int m;
void NOPE(){
cout<<-1;
exit(0);
}
int main(){
ios::sync_with_stdio(0); cin.tie(0);
cin>>n>>m;
ll mcnt=0, mn=0, mtmp=0, sum=0;
char S[MX]; int k;
for(int i=1; i<=m; i++){
cin>>(S+1)>>k;
ll now=0, low=0, cnt=0, tmp=0;
for(int i=1; S[i]!=0; i++){
if(S[i]=='M'){
cnt++;
now++;
}
else{
now--;
}
if(low>=now) low=now, tmp=cnt;
}
if(now>0){
ll gmin=sum+low;
if(mn>=gmin){
mn=gmin;
mtmp=mcnt+tmp;
}
}
else{
ll gmin=sum+now*(k-1)+low;
if(mn>=gmin){
mn=gmin;
mtmp=mcnt+cnt*(k-1)+tmp;
}
}
sum+=now*k;
mcnt+=cnt*k;
// cout<<now<<' '<<low<<' '<<cnt<<' '<<tmp<<'\n';
}
if(n<mcnt) NOPE();
ll need=max(0LL, sum-1-mn);
cout<<need;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
