結果

問題 No.2708 Jewel holder
ユーザー tipstar0125tipstar0125
提出日時 2024-03-31 14:11:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 105 ms / 2,000 ms
コード長 954 bytes
コンパイル時間 151 ms
コンパイル使用メモリ 82,056 KB
実行使用メモリ 76,612 KB
最終ジャッジ日時 2024-09-30 19:06:44
合計ジャッジ時間 1,809 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

H,W=list(map(int,input().split()))
A=[input() for _ in range(H)]

ans=0
for i in range(1<<(H+W-2)):
    n=i.bit_count()
    bit=i
    row=0
    col=0
    cnt=1
    ok=True
    for j in range(H+W-2):
        if (bit>>j)&1==0:
            if row+1>=H or A[row+1][col]=="#":
                ok=False
                break
            if A[row+1][col]=="x":
                if cnt==0:
                    ok=False
                    break
                cnt-=1
            if A[row+1][col]=="o":
                cnt+=1
            row+=1
        else:
            if col+1>=W or A[row][col+1]=="#":
                ok=False
                break
            if A[row][col+1]=="x":
                if cnt==0:
                    ok=False
                    break
                cnt-=1
            if A[row][col+1]=="o":
                cnt+=1
            col+=1
        # print(bin(bit),row,col,cnt)
    if ok and row==H-1 and col==W-1:ans+=1
print(ans)

0