Submission #310418

#TimeUsernameProblemLanguageResultExecution timeMemory
310418TemmieLinear Garden (IOI08_linear_garden)C++17
36 / 100
62 ms2460 KiB
#include <bits/stdc++.h> int pow(int x, int p, int m) { p %= m; int r = 1; while (p) { if (p & 1) r = (r * x) % m; x = (x * x) % m; p >>= 1; } return r; } int rem(int& x, int m) { x--; if (x == -1) x += m; return x; } int main() { std::ios::sync_with_stdio(0); std::cin.tie(0); int n, m; std::cin >> n >> m; std::string s; std::cin >> s; int l = 0, r = 0, now = 0, ans = 0; for (int i = 0; i < n; i++) { if (s[i] == 'L') now++, r = std::max(r, now); else { int rr = std::max(r, now + 1); int rn = n - i - 1; if (!(rr - l - 1)) ans = (ans + pow(2, rn >> 1, m) + pow(2, (rn + 1) >> 1, m)) % m, rem(ans, m); else if (!(rr - l - 2)) { if (now + 1 == rr - 1) ans = (ans + pow(2, (rn + 1) >> 1, m)) % m; else ans = (ans + pow(2, rn >> 1, m)) % m; } now--, l = std::min(l, now); } } std::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...