Language: C++

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>


using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define clear(arr, val) memset(arr, val, sizeof(arr))

#define rep(i, n) for (int i = 0; i < n; ++i)

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

typedef long long ll;
typedef pair<int, int> pint;

const double EPS = 1e-8;
const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };



int w, h;
char s[32][32];

int counter = 0;
//map<int, int> states;
short index[1 << 20];
int states[17777];
bool used_j[32];
void make_states(int p)
{
	if (p == w)
	{
		int s = 0;
		for (int i = 0; i < w; ++i)
			s |= used_j[i] << i;
		//int pos = states.size();
		//states[s] = pos;

		states[counter] = s;
		index[s] = counter++;
	}
	else
	{
		make_states(p + 1);
		if (p == 0 || !used_j[p - 1])
		{
			used_j[p] = true;
			make_states(p + 1);
			used_j[p] = false;
		}
	}
}
int main()
{
	cin >> h >> w;
	rep (i, h)
		cin >> s[i];
	make_states(0);

	const int mod = 100000;
	static int dp[401][17777];
	dp[0][0] = 1;
	for (int i = 0; i < w * h; ++i)
	{
		int x = i % w, y = i / w;
		//foreach (it, states)
		for (int j = 0; j < counter; ++j)
		{
			//int S = it->first;
			//int cur = dp[i][it->second];
			int S = states[j];
			int cur = dp[i][j];

			int T = ((S >> 1) << 2) & ((1 << w) - 1);
			int J = S & 1;

			if (s[y][x] == 'J' || s[y][x] == '?')
			{
				(dp[i + 1][index[T | (x < w - 1)]] += cur) %= mod;
			}

			if (s[y][x] == 'O' || s[y][x] == '?')
			{
				(dp[i + 1][index[T | (J ? (1 << 1) : 0)]] += cur) %= mod;
			}

			if (s[y][x] == 'I' || s[y][x] == '?')
			{
				if (!(S >> (w - 1) & 1))
					(dp[i + 1][index[T]] += cur) %= mod;
			}
		}
	}


	int hatena = 0;
	for (int i = 0; i < h; ++i)
		for (int j = 0; j < w; ++j)
			if (s[i][j] == '?')
				++hatena;
	int all_pattern = 1;
	for (int i = 0; i < hatena; ++i)
		(all_pattern *= 3) %= mod;

	int non_joi = 0;
	for (int i = 0; i < counter; ++i)
		(non_joi += dp[w * h][i]) %= mod;

	int res = (all_pattern - non_joi + mod) % mod;
	cout << res << endl;
	//cout << "all: " << all_pattern << endl;
	//cout << "non_joi: " << non_joi << endl;
}

Compiler output:
a.cc:58:20: error: 'short int index [1048576]' redeclared as different kind of entity
   58 | short index[1 << 20];
      |                    ^
In file included from /usr/include/string.h:462,
                 from /usr/include/c++/14/cstring:43,
                 from a.cc:3:
/usr/include/strings.h:50:20: note: previous declaration 'const char* index(const char*, int)'
   50 | extern const char *index (const char *__s, int __c)
      |                    ^~~~~
a.cc: In function 'void make_states(int)':
a.cc:72:22: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   72 |                 index[s] = counter++;
      |                      ^
a.cc: In function 'int main()':
a.cc:111:49: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
  111 |                                 (dp[i + 1][index[T | (x < w - 1)]] += cur) %= mod;
      |                                                 ^
a.cc:116:49: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
  116 |                                 (dp[i + 1][index[T | (J ? (1 << 1) : 0)]] += cur) %= mod;
      |                                                 ^
a.cc:122:57: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
  122 |                                         (dp[i + 1][index[T]] += cur) %= mod;
      |                                                         ^