Submission #842999

#TimeUsernameProblemLanguageResultExecution timeMemory
842999anha3k25cvpLinear Garden (IOI08_linear_garden)C++14
100 / 100
1158 ms18444 KiB
#include <bits/stdc++.h> #define ll long long #define ull unsigned long long #define dl double #define st first #define nd second #define II pair <int, int> using namespace std; const int N = 5 + 1e5; const int inf = 7 + 1e9; int main() { #define TASKNAME "" ios_base :: sync_with_stdio (0); cin.tie (0); if ( fopen( TASKNAME".inp", "r" ) ) { freopen (TASKNAME".inp", "r", stdin); freopen (TASKNAME".out", "w", stdout); } int n, m; string s; cin >> n >> m >> s; n = s.size(); vector <int> a(n + 1, 0); for (int i = 1; i <= n; i ++) a[i] = s[i - 1] == 'P'; vector <II> b(n + 1, {-1, -1}); int x = 2, y = 2; for (int i = 1; i <= n; i ++) { if (a[i] && x > 0) { int mi_ = min(x - 1, 1), ma_ = max(y - 1, 1); b[n - i] = {mi_, ma_ - mi_}; } if (!a[i]) { x = min(x - 1, 1); y = max(y - 1, 1); } else { x = min(x + 1, 3); y = max(y + 1, 3); } } vector <int> f(n + 1, 0); vector <vector <vector <vector <vector <int>>>>> g(2, vector <vector <vector <vector <int>>>> (5, vector <vector <vector <int>>> (3, vector <vector <int>> (5, vector <int> (3, 0))))); for (int mi = 0; mi <= 4; mi ++) for (int ma = mi; ma <= min(mi + 2, 4); ma ++) g[1][mi][ma - mi][mi][ma - mi] = 1; for (int num = 0; num <= n; num ++) for (int mi = 0; mi <= 4; mi ++) for (int ma = 0; ma <= min(4 - mi, 2); ma ++) { for (int i = 0; i <= 4; i ++) for (int delta = 0; delta <= min(4 - i, 2); delta ++) { g[0][mi][ma][i][delta] = g[1][mi][ma][i][delta]; g[1][mi][ma][i][delta] = 0; if (b[num].st == mi && b[num].nd == ma) f[num] = (f[num] + g[0][mi][ma][i][delta]) % m; } if (num == n) break; for (int i = 0; i <= 4; i ++) for (int delta = 0; delta <= min(4 - i, 2); delta ++) { int j = i + delta; if (i > 0) { int i_ = min(i - 1, 1), j_ = max(j - 1, 1); g[1][mi][ma][i_][j_ - i_] = (g[1][mi][ma][i_][j_ - i_] + g[0][mi][ma][i][delta]) % m; } if (j < 4) { int i_ = min(i + 1, 3), j_ = max(j + 1, 3); g[1][mi][ma][i_][j_ - i_] = (g[1][mi][ma][i_][j_ - i_] + g[0][mi][ma][i][delta]) % m; } } } int ans = 1; for (int i = 0; i <= n; i ++) ans = (ans + f[i]) % m; cout << ans; return 0; }

Compilation message (stderr)

linear_garden.cpp: In function 'int main()':
linear_garden.cpp:19:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         freopen (TASKNAME".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
linear_garden.cpp:20:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         freopen (TASKNAME".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...