mirror of
https://github.com/priyanshujain/messageboardbench.git
synced 2026-10-04 20:17:06 +00:00
Checkpoint experiments through SWE pilot v2
This commit is contained in:
1 parent
abacd5c5e1
commit
72d77018d8
845 files changed
+431756
-41
No files matched your search
@@ -0,0 +1,38 @@
|
||||
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: ((N+1) - (N-1)*((N-2)/N)^K) / 2
|
||||
# Derived from symmetry: q_K = 1/N + ((N-2)/N)^K * (N-1)/N
|
||||
# E_K = (N+1)/2 - (N-1)/2 * ((N-2)/N)^K ... actually
|
||||
# E_K = (N+1)/2 - (N-1)/2 * r^K with r=(N-2)/N
|
||||
# Equivalent to ((N+1) - (N-1)*r^K)/2
|
||||
n_mod = N % MOD
|
||||
inv_n = pow(n_mod, MOD - 2, MOD)
|
||||
r = (n_mod - 2) % MOD * inv_n % MOD
|
||||
p = pow(r, K, MOD)
|
||||
return ((n_mod + 1 - (n_mod - 1) * p) % MOD) * inv2 % MOD
|
||||
@@ -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-999c2cdda9c4",
|
||||
"--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": "83c3ade25cb0564639539d95374214e996ba1281c65c64529ae17d21a3115053",
|
||||
"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!")
|
||||
Reference in new issue
Block a user