Submission #109452

#TimeUsernameProblemLanguageResultExecution timeMemory
109452MetBLinear Garden (IOI08_linear_garden)C++14
Compilation error
0 ms0 KiB
#include <iostream>
#include <cstdlib>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <bitset>
#include <queue>
#include <math.h>
#include <stack>
#include <vector>
#include <string.h>
#include <random>
 
typedef long long ll;
 
const ll MOD = 1e9 + 7, INF = 1e18;
 
using namespace std;
 
string s;

ll n, d[1000000][5][5][5], m;

void add_self (int& a, ll b)
{
	a += b;
	if (a >= m) a -= m;
}

int main ()
{
	cin >> n >> m;
	d[0][2][3][3] = 1;


	for (ll i = 0; i < n; i++)
		for (ll j = 0; j < 5; j++)
			for (ll k = j; k < 5; k++)
				if (k - j <= 2)
				{
					for (ll f = j; f <= k; f++)
					{
						if (max (k, f + 1) - j <= 2) add_self (d[i + 1][j][max (k, f + 1)][f + 1], d[i][j][k][f]);
						if (k - min (j, f - 1) <= 2) add_self (d[i + 1][min (j, f - 1)][k][f - 1], d[i][j][k][f]);
					}
				}

	cin >> s;

	ll max_balance = 2, min_balance = 2, balance = 2, ans = 0;

	for (ll i = 0; i < n; i++)
	{
		if (s[i] == 'P')
		{
			for (ll j = 0; j < 5; j++)
				for (ll k = j; k < 5; k++)
					if (max (max_balance, k + balance - 2) - min (min_balance, j + balance - 2) <= 2)
					{
						for (ll f = j; f <= k; f++)
							add_self (ans, d[n - i - 1][j][k][f]);
					}

			balance--;
		}
		else balance++;


		max_balance = max (max_balance, balance);
		min_balance = min (min_balance, balance);
	}

	cout << (ans + 1) % m;
}

Compilation message (stderr)

linear_garden.cpp: In function 'int main()':
linear_garden.cpp:44:79: error: cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int'
       if (max (k, f + 1) - j <= 2) add_self (d[i + 1][j][max (k, f + 1)][f + 1], d[i][j][k][f]);
                                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
linear_garden.cpp:25:6: note:   initializing argument 1 of 'void add_self(int&, ll)'
 void add_self (int& a, ll b)
      ^~~~~~~~
linear_garden.cpp:45:79: error: cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int'
       if (k - min (j, f - 1) <= 2) add_self (d[i + 1][min (j, f - 1)][k][f - 1], d[i][j][k][f]);
                                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
linear_garden.cpp:25:6: note:   initializing argument 1 of 'void add_self(int&, ll)'
 void add_self (int& a, ll b)
      ^~~~~~~~
linear_garden.cpp:62:44: error: cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int'
        add_self (ans, d[n - i - 1][j][k][f]);
                                            ^
linear_garden.cpp:25:6: note:   initializing argument 1 of 'void add_self(int&, ll)'
 void add_self (int& a, ll b)
      ^~~~~~~~