Submission #262859

#TimeUsernameProblemLanguageResultExecution timeMemory
262859ElyesChaabouniLinear Garden (IOI08_linear_garden)C++14
Compilation error
0 ms0 KiB
/*#pragma GCC optimize("O3")*/
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp> 
//#define ordered_set tree<int, null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
#define eps 1e-9
#define MOD1 998244353
#define MOD2 1000000007
#define INV_10 299473306
#define INF 1000000000
#define PI 3.14159265358979323846
using namespace std;
int dp[1000000][9][2];
bool a[1000000];
int n, m, pp, ll;
int solve(int idx, int d, bool b)
{
	if(idx==n)
		return 1;
	if(dp[idx][d][b]!=-1)
		return dp[idx][d][b];
	dp[idx][d][b]=0;
	if(a[idx])
	{
		if(p < 2)
		{
			pp=d/3;
			ll=d%3;
			pp++;
			ll--;
			ll=max(ll, 0);
			dp[idx][d][b]+=solve(idx+1, pp*3+ll, b);
			dp[idx][d][b]%=m;
		}
		if(l < 2)
		{
			pp=d/3;
			ll=d%3;
			pp--;
			ll++;
			pp=max(0, pp);
			dp[idx][d][b]+=solve(idx+1, pp*3+ll, 1);
			dp[idx][d][b]%=m;
		}
	}
	else
	{
		if(l < 2)
		{
			pp=d/3;
			ll=d%3;
			pp--;
			ll++;
			pp=max(0, pp);
			dp[idx][d][b]+=solve(idx+1, pp*3+ll, b);
			dp[idx][d][b]%=m;
		}
		if(p < 2 && b)
		{
			pp=d/3;
			ll=d%3;
			pp++;
			ll--;
			ll=max(ll, 0);
			dp[idx][d][b]+=solve(idx+1, pp*3+ll, b);
			dp[idx][d][b]%=m;
		}
	}
	return dp[idx][d][b];
}
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin >> n >> m;
	char c;
	for(int i = 0; i < n; i++)
	{
		cin >> c;
		if(c=='P')
			a[i]=1;
	}
	for(int i = 0; i <= n; i++)
			for(int k = 0; k < 9; k++)
				for(int l = 0; l < 3; l++)
					dp[i][k][l]=-1;
	cout << solve(0, 0, 0) << '\n';
}
//size

Compilation message (stderr)

linear_garden.cpp: In function 'int solve(int, int, bool)':
linear_garden.cpp:25:6: error: 'p' was not declared in this scope
   25 |   if(p < 2)
      |      ^
linear_garden.cpp:35:6: error: 'l' was not declared in this scope
   35 |   if(l < 2)
      |      ^
linear_garden.cpp:48:6: error: 'l' was not declared in this scope
   48 |   if(l < 2)
      |      ^
linear_garden.cpp:58:6: error: 'p' was not declared in this scope
   58 |   if(p < 2 && b)
      |      ^