Submission #1022764

#TimeUsernameProblemLanguageResultExecution timeMemory
1022764nmtsLinear Garden (IOI08_linear_garden)C++17
0 / 100
3 ms600 KiB
#include <bits/stdc++.h> #define file(name) freopen(name".inp" , " r " , stdin);freopen(name".out" , " w " , stdout) #define faster ios_base :: sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0) ; #define dp(i , mi , ma) dp[i][mi + 2][ma] using namespace std; int n , m; string s; int dp[1000000][3][3]; void solve() { cin >> n >> m >> s; for (int mi = -2; mi <= 0; ++mi) for (int ma = 0; ma <= 2; ++ma) dp(n + 1, mi, ma) = 1; for (int i = n; i >= 1; --i) { for (int mi = -2; mi <= 0; ++mi) { for (int ma = 0; ma <= 2; ++ma) { if (mi > -2) dp(i, mi, ma) += dp(i + 1, mi - 1, max(0, ma - 1)); if (ma < 2) dp(i, mi, ma) += dp(i + 1, min(0, mi + 1), ma + 1); dp(i, mi, ma) %= m; } } } s = " " + s; int ans = 1; for (int i = 1 , mi = 0 , ma = 0 ; i <= n ; ++i) if (s[i] == 'L') { mi--; ma = max(0 , ma - 1); } else { if (mi > -2) ans = (ans + dp(i + 1 , mi - 1 , max(mi - 1 , 0))) % m; ma++; mi = min(0 , mi + 1); } cout << ans << endl; } int32_t main() { faster; #ifndef ONLINE_JUDGE file("txt"); #else // online submission #endif // int t ; cin >> t ; while (t--) solve(); return 0; }

Compilation message (stderr)

linear_garden.cpp: In function 'int32_t main()':
linear_garden.cpp:3:27: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define file(name) freopen(name".inp" , " r " , stdin);freopen(name".out" , " w " , stdout)
      |                    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
linear_garden.cpp:59:5: note: in expansion of macro 'file'
   59 |     file("txt");
      |     ^~~~
linear_garden.cpp:3:63: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define file(name) freopen(name".inp" , " r " , stdin);freopen(name".out" , " w " , stdout)
      |                                                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
linear_garden.cpp:59:5: note: in expansion of macro 'file'
   59 |     file("txt");
      |     ^~~~
#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...