제출 #328911

#제출 시각아이디문제언어결과실행 시간메모리
328911sofapudenLinear Garden (IOI08_linear_garden)C++14
100 / 100
114 ms2440 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...