제출 #757290

#제출 시각아이디문제언어결과실행 시간메모리
757290SanguineChameleonLinear Garden (IOI08_linear_garden)C++17
100 / 100
30 ms9120 KiB
#include <bits/stdc++.h> using namespace std; void just_do_it(); int main() { #ifdef KAMIRULEZ freopen("kamirulez.inp", "r", stdin); freopen("kamirulez.out", "w", stdout); #endif ios_base::sync_with_stdio(0); cin.tie(0); just_do_it(); return 0; } const int maxn = 1e6 + 20; int a[maxn]; int pw[maxn]; void just_do_it() { int n, mod; cin >> n >> mod; pw[0] = 1; for (int i = 1; i <= n; i++) { pw[i] = pw[i - 1] * 2 % mod; } a[0] = -1; for (int i = 1; i <= n; i++) { char c; cin >> c; if (c == 'L') { a[i] = 0; } if (c == 'P') { a[i] = 1; } } int res = 1; int cur = -1; for (int i = 1; i <= n; i++) { if (a[i] == 1) { if (a[i - 1] == 0) { if (cur != 0) { res += pw[(n - i) / 2]; res %= mod; } } else { if (cur != 0) { res += pw[(n - i + 1) / 2] + mod - 1; res %= mod; } if (cur != 1) { res += pw[(n - i) / 2] + mod - 1; res %= mod; } res += 1; res %= mod; } } cur = (a[i - 1] == a[i] ? a[i] : cur); } cout << res; }
#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...