Language: C++

#include <string>
#include <vector>
#include <iostream>
 
#pragma warning(disable : 4996)
 
#define mod 100000
 
using namespace std;
 
int H, W, dp[400][1 << 19][3][2]; string M[20];
 
int main()
{
    scanf("%d", &H);
    scanf("%d", &W);
 
    for (int i = 0; i < H; i++) cin >> M[i];
 
    if (M[0][0] == 'J' || M[0][0] == '?') dp[0][0][0][0] = 1;
    if (M[0][0] == 'O' || M[0][0] == '?') dp[0][0][1][0] = 1;
    if (M[0][0] == 'I' || M[0][0] == '?') dp[0][0][2][0] = 1;
 
    for (int i = 0; i < H * W - 1; i++)
    {
        for (int j = 0; j < (1 << (W - 1)); j++)
        {
            char c = M[(i + 1) / W][(i + 1) % W];
 
            int nxt = (j << 1) % (1 << (W - 1));
 
            int sum0 = (dp[i][j][0][0] + dp[i][j][1][0] + dp[i][j][2][0]) % mod;
            int sum1 = (dp[i][j][0][1] + dp[i][j][1][1] + dp[i][j][2][1]) % mod;
 
            if (c == 'J' || c == '?')
            {
                dp[i + 1][nxt][0][0] += sum0;
                dp[i + 1][nxt][0][1] += sum1;
 
                dp[i + 1][nxt][0][0] %= mod;
                dp[i + 1][nxt][0][1] %= mod;
            }
 
            if (c == 'O' || c == '?')
            {
                if ((M[i / W][i % W] == 'J' || M[i / W][i % W] == '?') && i % W != W - 1)
                {
                    dp[i + 1][nxt + 1][1][0] += dp[i][j][0][0];
                    dp[i + 1][nxt + 1][1][1] += dp[i][j][0][1];
 
                    dp[i + 1][nxt + 1][1][0] %= mod;
                    dp[i + 1][nxt + 1][1][1] %= mod;
 
                    dp[i + 1][nxt][1][0] += (sum0 - dp[i][j][0][0] + mod);
                    dp[i + 1][nxt][1][1] += (sum1 - dp[i][j][0][1] + mod);
 
                    dp[i + 1][nxt][1][0] %= mod;
                    dp[i + 1][nxt][1][1] %= mod;
                }
                else
                {
                    dp[i + 1][nxt][1][0] += sum0;
                    dp[i + 1][nxt][1][1] += sum1;
 
                    dp[i + 1][nxt][1][0] %= mod;
                    dp[i + 1][nxt][1][1] %= mod;
                }
            }
 
            if (c == 'I' || c == '?')
            {
                if (j & (1 << (W - 2)))
                {
                    dp[i + 1][nxt][2][1] += sum0;
                }
                else
                {
                    dp[i + 1][nxt][2][0] += sum0;
                }
 
                dp[i + 1][nxt][2][1] += sum1;
 
                dp[i + 1][nxt][2][0] %= mod;
                dp[i + 1][nxt][2][1] %= mod;
            }
        }
    }
 
    int ret = 0;
 
    for (int i = 0; i < (1 << (W - 1)); i++)
    {
        for (int j = 0; j < 3; j++)
        {
            ret += dp[H * W - 1][i][j][1];
            ret %= mod;
        }
    }
 
    printf("%d\n", ret);
 
    return 0;
}

Compiler output:
/tmp/ccdM8GIA.o: in function `main':
a.cc:(.text+0x5c): relocation truncated to fit: R_X86_64_PC32 against symbol `M[abi:cxx11]' defined in .bss section in /tmp/ccdM8GIA.o
a.cc:(.text+0x8c): relocation truncated to fit: R_X86_64_PC32 against symbol `M[abi:cxx11]' defined in .bss section in /tmp/ccdM8GIA.o
a.cc:(.text+0xa7): relocation truncated to fit: R_X86_64_PC32 against symbol `M[abi:cxx11]' defined in .bss section in /tmp/ccdM8GIA.o
a.cc:(.text+0xdc): relocation truncated to fit: R_X86_64_PC32 against symbol `M[abi:cxx11]' defined in .bss section in /tmp/ccdM8GIA.o
a.cc:(.text+0xf7): relocation truncated to fit: R_X86_64_PC32 against symbol `M[abi:cxx11]' defined in .bss section in /tmp/ccdM8GIA.o
a.cc:(.text+0x12c): relocation truncated to fit: R_X86_64_PC32 against symbol `M[abi:cxx11]' defined in .bss section in /tmp/ccdM8GIA.o
a.cc:(.text+0x147): relocation truncated to fit: R_X86_64_PC32 against symbol `M[abi:cxx11]' defined in .bss section in /tmp/ccdM8GIA.o
a.cc:(.text+0x1a7): relocation truncated to fit: R_X86_64_PC32 against symbol `M[abi:cxx11]' defined in .bss section in /tmp/ccdM8GIA.o
a.cc:(.text+0x624): relocation truncated to fit: R_X86_64_PC32 against symbol `M[abi:cxx11]' defined in .bss section in /tmp/ccdM8GIA.o
a.cc:(.text+0x668): relocation truncated to fit: R_X86_64_PC32 against symbol `M[abi:cxx11]' defined in .bss section in /tmp/ccdM8GIA.o
/tmp/ccdM8GIA.o: in function `__tcf_0':
a.cc:(.text+0x12a9): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status