Submission #1340250

#TimeUsernameProblemLanguageResultExecution timeMemory
1340250JungPSLinear Garden (IOI08_linear_garden)C++20
Compilation error
0 ms0 KiB
#include<bits/stdc++.h>
using namespace std;

int n,m;
string str;
int dp[1000007][4][4];

signed main(){
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    cin >> n >> m;
    cin >> str;
    for(int i=n;i>=0;--i){
        for(int mn=0;mn<3;++mn){
            for(int mx=0;mx<3;++mx){
                if(i==n){
                    dp[i][mn][mx]=1;
                    continue;
                }
				dp[i][mn][mx]=dp[i+1][max(0LL,mn-1)][mx+1]+dp[i+1][mn+1][max(0LL,mx-1)];
                dp[i][mn][mx]%=m;
            }
        }
    }
    int ans=1,mx=0,mn=0;
	for(int i=0;i<n;++i){
		if(str[i]=='L'){
            ++mn;
            mx=max(0LL,mx-1);
			continue;
		}
        ans+=dp[i+1][mn+1][max(0LL,mx-1)];
        ans%=m;
        mn=max(0LL,mn-1);
		++mx;
	}
    cout << ans;
}

Compilation message (stderr)

linear_garden.cpp: In function 'int main()':
linear_garden.cpp:19:58: error: no matching function for call to 'max(long long int, int)'
   19 |                                 dp[i][mn][mx]=dp[i+1][max(0LL,mn-1)][mx+1]+dp[i+1][mn+1][max(0LL,mx-1)];
      |                                                       ~~~^~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51,
                 from linear_garden.cpp:1:
/usr/include/c++/13/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
linear_garden.cpp:19:58: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   19 |                                 dp[i][mn][mx]=dp[i+1][max(0LL,mn-1)][mx+1]+dp[i+1][mn+1][max(0LL,mx-1)];
      |                                                       ~~~^~~~~~~~~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note:   template argument deduction/substitution failed:
linear_garden.cpp:19:58: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   19 |                                 dp[i][mn][mx]=dp[i+1][max(0LL,mn-1)][mx+1]+dp[i+1][mn+1][max(0LL,mx-1)];
      |                                                       ~~~^~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:61:
/usr/include/c++/13/bits/stl_algo.h:5795:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5795 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5795:5: note:   template argument deduction/substitution failed:
linear_garden.cpp:19:58: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   19 |                                 dp[i][mn][mx]=dp[i+1][max(0LL,mn-1)][mx+1]+dp[i+1][mn+1][max(0LL,mx-1)];
      |                                                       ~~~^~~~~~~~~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5805 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note:   template argument deduction/substitution failed:
linear_garden.cpp:19:58: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   19 |                                 dp[i][mn][mx]=dp[i+1][max(0LL,mn-1)][mx+1]+dp[i+1][mn+1][max(0LL,mx-1)];
      |                                                       ~~~^~~~~~~~~~
linear_garden.cpp:19:93: error: no matching function for call to 'max(long long int, int)'
   19 |                                 dp[i][mn][mx]=dp[i+1][max(0LL,mn-1)][mx+1]+dp[i+1][mn+1][max(0LL,mx-1)];
      |                                                                                          ~~~^~~~~~~~~~
/usr/include/c++/13/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
linear_garden.cpp:19:93: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   19 |                                 dp[i][mn][mx]=dp[i+1][max(0LL,mn-1)][mx+1]+dp[i+1][mn+1][max(0LL,mx-1)];
      |                                                                                          ~~~^~~~~~~~~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note:   template argument deduction/substitution failed:
linear_garden.cpp:19:93: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   19 |                                 dp[i][mn][mx]=dp[i+1][max(0LL,mn-1)][mx+1]+dp[i+1][mn+1][max(0LL,mx-1)];
      |                                                                                          ~~~^~~~~~~~~~
/usr/include/c++/13/bits/stl_algo.h:5795:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5795 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5795:5: note:   template argument deduction/substitution failed:
linear_garden.cpp:19:93: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   19 |                                 dp[i][mn][mx]=dp[i+1][max(0LL,mn-1)][mx+1]+dp[i+1][mn+1][max(0LL,mx-1)];
      |                                                                                          ~~~^~~~~~~~~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5805 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note:   template argument deduction/substitution failed:
linear_garden.cpp:19:93: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   19 |                                 dp[i][mn][mx]=dp[i+1][max(0LL,mn-1)][mx+1]+dp[i+1][mn+1][max(0LL,mx-1)];
      |                                                                                          ~~~^~~~~~~~~~
linear_garden.cpp:28:19: error: no matching function for call to 'max(long long int, int)'
   28 |             mx=max(0LL,mx-1);
      |                ~~~^~~~~~~~~~
/usr/include/c++/13/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
linear_garden.cpp:28:19: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   28 |             mx=max(0LL,mx-1);
      |                ~~~^~~~~~~~~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note:   template argument deduction/substitution failed:
linear_garden.cpp:28:19: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   28 |             mx=max(0LL,mx-1);
      |                ~~~^~~~~~~~~~
/usr/include/c++/13/bits/stl_algo.h:5795:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5795 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5795:5: note:   template argument deduction/substitution failed:
linear_garden.cpp:28:19: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   28 |             mx=max(0LL,mx-1);
      |                ~~~^~~~~~~~~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5805 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note:   template argument deduction/substitution failed:
linear_garden.cpp:28:19: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   28 |             mx=max(0LL,mx-1);
      |                ~~~^~~~~~~~~~
linear_garden.cpp:31:31: error: no matching function for call to 'max(long long int, int)'
   31 |         ans+=dp[i+1][mn+1][max(0LL,mx-1)];
      |                            ~~~^~~~~~~~~~
/usr/include/c++/13/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
linear_garden.cpp:31:31: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   31 |         ans+=dp[i+1][mn+1][max(0LL,mx-1)];
      |                            ~~~^~~~~~~~~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note:   template argument deduction/substitution failed:
linear_garden.cpp:31:31: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   31 |         ans+=dp[i+1][mn+1][max(0LL,mx-1)];
      |                            ~~~^~~~~~~~~~
/usr/include/c++/13/bits/stl_algo.h:5795:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5795 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5795:5: note:   template argument deduction/substitution failed:
linear_garden.cpp:31:31: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   31 |         ans+=dp[i+1][mn+1][max(0LL,mx-1)];
      |                            ~~~^~~~~~~~~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5805 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note:   template argument deduction/substitution failed:
linear_garden.cpp:31:31: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   31 |         ans+=dp[i+1][mn+1][max(0LL,mx-1)];
      |                            ~~~^~~~~~~~~~
linear_garden.cpp:33:15: error: no matching function for call to 'max(long long int, int)'
   33 |         mn=max(0LL,mn-1);
      |            ~~~^~~~~~~~~~
/usr/include/c++/13/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
linear_garden.cpp:33:15: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   33 |         mn=max(0LL,mn-1);
      |            ~~~^~~~~~~~~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note:   template argument deduction/substitution failed:
linear_garden.cpp:33:15: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   33 |         mn=max(0LL,mn-1);
      |            ~~~^~~~~~~~~~
/usr/include/c++/13/bits/stl_algo.h:5795:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5795 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5795:5: note:   template argument deduction/substitution failed:
linear_garden.cpp:33:15: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   33 |         mn=max(0LL,mn-1);
      |            ~~~^~~~~~~~~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5805 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note:   template argument deduction/substitution failed:
linear_garden.cpp:33:15: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   33 |         mn=max(0LL,mn-1);
      |            ~~~^~~~~~~~~~