Submission #535154

#TimeUsernameProblemLanguageResultExecution timeMemory
535154cig32Linear Garden (IOI08_linear_garden)C++17
Compilation error
0 ms0 KiB
#include "bits/stdc++.h" using namespace std; const int MAXN = 2e5 + 10; const int MOD = 1e9 + 7; //#define int long long mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count()); int rnd(int x, int y) { int u = uniform_int_distribution<int>(x, y)(rng); return u; } int bm(int b, int p) { if(p==0) return 1; int r = bm(b, p/2); if(p&1) return (((r*r) % MOD) * b) % MOD; return (r*r) % MOD; } int inv(int b) { return bm(b, MOD-2); } int f[MAXN]; int nCr(int n, int r) { int ans = f[n]; ans *= inv(f[r]); ans %= MOD; ans *= inv(f[n-r]); ans %= MOD; return ans; } void precomp() { f[0] = 1; for(int i=1; i<MAXN; i++) f[i] = (f[i-1] * i) % MOD; } void solve(int tc) { int n, m; cin >> n >> m; string s; cin >> s; int dp[n+1][3][3]; for(int i=0; i<=n; i++) { for(int j=0; j<3; j++) { for(int k=0; k<3; k++) { dp[i][j][k] = 0; } } } dp[1][0][1] = 1; dp[1][1][0] = 1; for(int i=2; i<=n; i++) { for(int j=0; j<3; j++) { for(int k=0; k<3; k++) { //final = L if(k > 0 && j < 2) { dp[i][j][k] += dp[i - 1][j + 1][k - 1]; if(j == 0) dp[i][j][k] += dp[i - 1][0][k - 1]; dp[i][j][k] %= m; } //final = P if(k < 2 && j > 0) { dp[i][j][k] += dp[i - 1][j - 1][k + 1]; if(k == 0) dp[i][j][k] += dp[i - 1][j - 1][0]; dp[i][j][k] %= m; } } } } dp[0][0][0] = 1; int ans = 0; int ma = 0, mi = 0; // take absolute value for(int i=0; i<n; i++) { if(s[i] == 'P') { int new_ma = max(0ll, ma - 1); int new_mi = mi + 1; for(int j=0; j<3; j++) { for(int k=0; k<3; k++) { if(j + new_ma <= 2 && k + new_mi <= 2) { ans += dp[n - i - 1][j][k]; ans %= m; } } } ma = ma + 1; mi = max(0ll, mi - 1); if(ma > 2) break; } else { ma = max(0ll, ma - 1); mi = mi + 1; if(mi > 2) break; } } cout << (ans + 1) % m << '\n'; } int32_t main(){ precomp(); ios::sync_with_stdio(0); cin.tie(0); int t = 1; //cin >> t; for(int i=1; i<=t; i++) solve(i); }

Compilation message (stderr)

linear_garden.cpp: In function 'void solve(int)':
linear_garden.cpp:68:35: error: no matching function for call to 'max(long long int, int)'
   68 |       int new_ma = max(0ll, ma - 1);
      |                                   ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from linear_garden.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
linear_garden.cpp:68:35: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   68 |       int new_ma = max(0ll, ma - 1);
      |                                   ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from linear_garden.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
linear_garden.cpp:68:35: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   68 |       int new_ma = max(0ll, ma - 1);
      |                                   ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from linear_garden.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
linear_garden.cpp:68:35: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   68 |       int new_ma = max(0ll, ma - 1);
      |                                   ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from linear_garden.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
linear_garden.cpp:68:35: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   68 |       int new_ma = max(0ll, ma - 1);
      |                                   ^
linear_garden.cpp:79:27: error: no matching function for call to 'max(long long int, int)'
   79 |       mi = max(0ll, mi - 1);
      |                           ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from linear_garden.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
linear_garden.cpp:79:27: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   79 |       mi = max(0ll, mi - 1);
      |                           ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from linear_garden.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
linear_garden.cpp:79:27: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   79 |       mi = max(0ll, mi - 1);
      |                           ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from linear_garden.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
linear_garden.cpp:79:27: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   79 |       mi = max(0ll, mi - 1);
      |                           ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from linear_garden.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
linear_garden.cpp:79:27: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   79 |       mi = max(0ll, mi - 1);
      |                           ^
linear_garden.cpp:83:27: error: no matching function for call to 'max(long long int, int)'
   83 |       ma = max(0ll, ma - 1);
      |                           ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from linear_garden.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
linear_garden.cpp:83:27: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   83 |       ma = max(0ll, ma - 1);
      |                           ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from linear_garden.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
linear_garden.cpp:83:27: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   83 |       ma = max(0ll, ma - 1);
      |                           ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from linear_garden.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
linear_garden.cpp:83:27: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   83 |       ma = max(0ll, ma - 1);
      |                           ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from linear_garden.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
linear_garden.cpp:83:27: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   83 |       ma = max(0ll, ma - 1);
      |                           ^