제출 #260540

#제출 시각아이디문제언어결과실행 시간메모리
260540WLZLinear Garden (IOI08_linear_garden)C++14
100 / 100
22 ms10060 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; long long MOD; string s; cin >> n >> MOD >> s; vector<long long> pw(n + 1); pw[0] = 1; for (int i = 1; i <= n; i++) { pw[i] = (pw[i - 1] * 2) % MOD; } long long ans = 0; int lo = 0, hi = 0, cur = 0; int k = n; for (auto& c : s) { k--; if (c == 'P') { int tmp = cur + 1; int tmp_lo = min(lo, tmp); int tmp_hi = max(hi, tmp); if (tmp_hi - tmp_lo == 2) { if (tmp == (tmp_hi + tmp_lo) / 2) { ans = (ans + pw[(k + 1) / 2]) % MOD; } else { ans = (ans + pw[k / 2]) % MOD; } } else if (tmp_hi - tmp_lo == 1) { ans = ((ans + pw[k / 2] + pw[(k + 1) / 2] - 1) % MOD + MOD) % MOD; } } if (c == 'L') { cur++; } else { cur--; } lo = min(lo, cur); hi = max(hi, cur); } cout << (ans + 1) % MOD << '\n'; return 0; }
#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...