結果
| 問題 |
No.3117 Reversible Tile
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-04-18 22:30:22 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,343 bytes |
| コンパイル時間 | 171 ms |
| コンパイル使用メモリ | 12,160 KB |
| 実行使用メモリ | 26,688 KB |
| 最終ジャッジ日時 | 2025-04-18 22:30:31 |
| 合計ジャッジ時間 | 8,762 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 3 |
| other | TLE * 1 -- * 23 |
ソースコード
MOD = 998244353
def solve_tile_problem(N, M, A):
# dp[i][j] = number of ways to reach state up to tile i with j operations
dp = [0] * (N + 1)
dp[0] = 1 # base case: 0 tiles, 0 operations, 1 way
for op in range(M):
# Use difference array technique to simulate flipping
new_dp = [0] * (N + 2)
for l in range(N):
for r in range(l, N):
new_dp[l] = (new_dp[l] + dp[l]) % MOD
new_dp[r + 1] = (new_dp[r + 1] - dp[l]) % MOD
# Apply prefix sum to get actual counts
for i in range(1, N + 1):
new_dp[i] = (new_dp[i] + new_dp[i - 1]) % MOD
# Move new_dp to dp for next round
dp = new_dp[:N + 1]
# Now count how many dp values match final configuration A
result = 0
for i in range(N + 1):
valid = True
for j in range(N):
flips = 0
# simulate number of flips at position j
for k in range(i):
if k <= j:
flips += 1
if flips % 2 != A[j]:
valid = False
break
if valid:
result = (result + dp[i]) % MOD
return result
# Example usage:
N, M = map(int, input().split())
A = list(map(int, input().split()))
print(solve_tile_problem(N, M, A))