이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int ll
using namespace std;
typedef long long int;
int M;
int po(int a, int b){
int _a = a, _b = b;
int ret = 1;
while(_b){
if(_b&1){ret*=_a;ret%=M;}
_a*=_a;
_a%=M;
_b>>=1;
}
return ret;
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int n; cin >> n >> M;
string s; cin >> s;
int l = 0, r = 0, ans = 0, now = 0;
for(int i = 0; i < n; ++i){
if(s[i] == 'L'){now++, r = max(r,now);continue;}
int rb = max(r,now+1);
int rb2 = n-i-1;
if(rb-l == 1){
ans+=po(2,rb2>>1);
ans+=po(2,(rb2+1)>>1);
ans--;
ans+=M;
ans%=M;
}
else if(rb-l == 2){
if(now+2==rb)ans+=po(2,(rb2+1)>>1);
else ans+=po(2,rb2>>1);
}
now--, l = min(l,now);
}
cout << (ans+1)%M << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |