Submission #466842

#TimeUsernameProblemLanguageResultExecution timeMemory
466842dutchLinear Garden (IOI08_linear_garden)C++17
100 / 100
183 ms1272 KiB
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1e6; int N, M, dp[2][3][3], result; char S[MAX_N]; #define s(i) (S[i] == 'P') signed main(){ cin.tie(0)->sync_with_stdio(0); scanf("%d%d\n", &N, &M); fread(S, 1, N, stdin); dp[0][0][0] = 1; for(int i=N; --i>=0; ){ int prev[2][3][3] = {}; swap(prev, dp); for(bool a : {0, 1}){ for(int x : {0, 1, 2}){ for(int y : {0, 1, 2}){ if(x < 2) (dp[!s(i) && a][x + 1][max(y - 1, 0)] += prev[a][x][y]) %= M; if(y < 2) (dp[!s(i) || a][max(x - 1, 0)][y + 1] += prev[a][x][y]) %= M; } } } } for(int x : {0, 1, 2}) for(int y : {0, 1, 2}) (result += dp[0][x][y]) %= M; cout << result; }

Compilation message (stderr)

linear_garden.cpp: In function 'int main()':
linear_garden.cpp:14:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |  scanf("%d%d\n", &N, &M);
      |  ~~~~~^~~~~~~~~~~~~~~~~~
linear_garden.cpp:15:7: warning: ignoring return value of 'size_t fread(void*, size_t, size_t, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |  fread(S, 1, N, stdin);
      |  ~~~~~^~~~~~~~~~~~~~~~
#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...