제출 #538299

#제출 시각아이디문제언어결과실행 시간메모리
538299timreizinLinear Garden (IOI08_linear_garden)C++17
100 / 100
19 ms10228 KiB
#include <iostream> #include <vector> #include <queue> #include <algorithm> #include <array> #include <set> #include <string> using namespace std; using ll = long long; int main() { cin.tie(0)->sync_with_stdio(0); int n; ll m; string s; cin >> n >> m >> s; ll res = 1; array<ll, 1000001> powers; powers[0] = 1; for (ll i = 1; i <= 1e6; ++i) powers[i] = (powers[i - 1] * 2) % m; int pref = 0, maxP = 0, minP = 0; for (int i = 0; i < n; ++i) { if (s[i] == 'P') { --pref; int nmax = max(maxP, pref), nmin = min(minP, pref); if (nmax - nmin <= 2) { if (nmax - nmin == 2) res += (pref != nmax && pref != nmin ? powers[(n - i) / 2] : powers[(n - i - 1) / 2]); else { res += powers[(n - i) / 2] + powers[(n - i - 1) / 2] - 1; if (res >= m) res -= m; } if (res >= m) res -= m; } ++pref; } pref += (s[i] == 'P' ? 1 : -1); maxP = max(maxP, pref); minP = max(minP, pref); } cout << res; 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...