Checkpoint experiments through SWE pilot v2

This commit is contained in:
pj committed 2026-09-15 15:46:10 +05:30
1 parent abacd5c5e1
commit 72d77018d8
845 files changed
+431756 -41

No files matched your search

@@ -0,0 +1,40 @@
def expected_black_ball_position(N: int, K: int) -> int:
""" There are N-1 white balls and one black ball arranged in a row, with the black ball
initially at the leftmost position. Takahashi performs K operations, where each operation
consists of:
- Choose two integers a and b uniformly at random between 1 and N, inclusive
- If a ≠ b, swap the a-th and b-th balls from the left
Find the expected position of the black ball after K operations, modulo 998244353.
The result is returned as an integer R where R × Q ≡ P (mod 998244353), where P/Q is
the expected value expressed as an irreducible fraction.
Args:
N: Total number of balls (1 ≤ N ≤ 998244352)
K: Number of operations (1 ≤ K ≤ 10^5)
Returns:
The expected position modulo 998244353
>>> expected_black_ball_position(2, 1)
499122178
>>> expected_black_ball_position(3, 2)
554580198
>>> expected_black_ball_position(4, 4)
592707587
"""
MOD = 998244353
inv2 = (MOD + 1) // 2 # 499122177
# Expected value E_K = ((N+1) - (N-1)*((N-2)/N)^K)/2
# Compute modulo MOD.
# For N=1 the second term vanishes (N-1=0), result is 1.
n_mod = N % MOD
n_plus_1 = (N + 1) % MOD
n_minus_1 = (N - 1) % MOD
inv_n = pow(n_mod, MOD - 2, MOD)
r = (N - 2) % MOD * inv_n % MOD
term = pow(r, K, MOD)
res = (n_plus_1 - n_minus_1 * term) % MOD
res = res * inv2 % MOD
return res
@@ -0,0 +1,3 @@
import runpy
runpy.run_path('/workspace/test.py', run_name='__main__')
print('REPLAY_COMPLETED')
@@ -0,0 +1,37 @@
{
"create_command": [
"docker",
"create",
"--name",
"board-artifact-validation-bc0db2ed8dd6",
"--network",
"none",
"--memory",
"512m",
"--pids-limit",
"64",
"--cap-drop",
"ALL",
"--security-opt",
"no-new-privileges",
"--user",
"65534:65534",
"--workdir",
"/workspace",
"aisiuk/inspect-tool-support",
"python3",
"-B",
"/workspace/probe.py"
],
"network_mode": "none",
"mounts": [],
"image_id": "sha256:fb045da8203aea656785c758f7147b003cfe21f213e9048a38be0a33242a5b3d",
"docker_start_exit_code": 0,
"container_exit_code": 0,
"timed_out": false,
"files_sha256": {
"func.py": "4079fb75956b2f291bba3f7d06537dc45faadbde5f588a1431f8376e52cbfb66",
"test.py": "f4361d7e31aef9f46f42b030037702ffb2dc505511aa6a99fdd93d1316607678",
"probe.py": "010f28d35c16feb589ee22de82f1b579e04fc1f3f415862e2db86598e230b5ef"
}
}
Whitespace-only changes.
@@ -0,0 +1,2 @@
All tests passed!
REPLAY_COMPLETED
@@ -0,0 +1,33 @@
from func import expected_black_ball_position
def test_func(candidate):
# Sample test cases
assert candidate(2, 1) == 499122178
assert candidate(3, 2) == 554580198
assert candidate(4, 4) == 592707587
# Additional test cases
assert candidate(92724482, 8713) == 397187210
assert candidate(42952, 42770) == 3846140
assert candidate(998244352, 100000) == 296595689
assert candidate(87868, 84659) == 469774635
assert candidate(1, 1) == 1
assert candidate(73, 2890) == 757452161
assert candidate(84789430, 17447) == 571416630
assert candidate(324383216, 75454) == 492179107
assert candidate(11655411, 67422) == 90043236
assert candidate(159870726, 60658) == 686981596
assert candidate(9, 89855) == 3867007
assert candidate(85, 39232) == 566906027
assert candidate(1, 100000) == 1
assert candidate(48020, 79364) == 191000302
assert candidate(795705262, 33277) == 6449814
assert candidate(82330, 30021) == 205041562
assert candidate(95, 82089) == 603320441
assert candidate(164026938, 72649) == 390346149
assert candidate(3492853, 52547) == 341797331
assert candidate(196203458, 63938) == 743047251
if __name__ == "__main__":
test_func(expected_black_ball_position)
print("All tests passed!")