Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Use abc200_b #190

Merged
merged 3 commits into from
Aug 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ Please check also the [gallery](https://kmyk.github.io/Jikka/gallery).
- :heavy_check_mark: AC `dp_z-kubaru.py`
- The Kubaru DP version of `dp_z-morau.py`.
- submission at v5.1.0.0: <https://atcoder.jp/contests/dp/submissions/24701829>
- :heavy_check_mark: AC `abc200_b.py`
- AtCoder Beginner Contest 200 [B - 200th ABC-200](https://atcoder.jp/contests/abc200/tasks/abc200_b)
- AC with a naive solution / 愚直解が AC
- submission at 76461f7b62c615281d2821ea0445e5bd6e316de8: <https://atcoder.jp/contests/abc200/submissions/25282153>
- :heavy_check_mark: AC `abc203_b.py`
- AtCoder Beginner Contest 203 [B - AtCoder Condominium](https://atcoder.jp/contests/abc203/tasks/abc203_b)
- AC with a naive solution using `sum(List[int])` / 愚直解が AC `sum(List[int])`を使用
Expand Down
File renamed without changes.
15 changes: 15 additions & 0 deletions examples/data/abc200_b.random.generator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env python3
# usage: $ oj generate-input 'python3 generate.py'
# usage: $ oj generate-input --hack-actual=./a.out --hack-expected=./naive 'python3 generate.py'
import random


# generated by oj-template v4.8.0 (https://github.com/online-judge-tools/template-generator)
def main():
N = random.randint(1, 10**5)
K = random.randint(1, 20)
print(N, K)


if __name__ == "__main__":
main()
1 change: 1 addition & 0 deletions examples/data/abc200_b.sample-1.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2021 4
1 change: 1 addition & 0 deletions examples/data/abc200_b.sample-1.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
50531
1 change: 1 addition & 0 deletions examples/data/abc200_b.sample-2.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
40000 2
1 change: 1 addition & 0 deletions examples/data/abc200_b.sample-2.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
1 change: 1 addition & 0 deletions examples/data/abc200_b.sample-3.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8691 20
1 change: 1 addition & 0 deletions examples/data/abc200_b.sample-3.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
84875488281
22 changes: 22 additions & 0 deletions examples/data/abc200_b.solver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python3
# https://atcoder.jp/contests/abc200/submissions/22401491


def solve(n: int, k: int) -> int:
for _ in range(k):
if n % 200 == 0:
n //= 200
else:
n = n * 1000 + 200
return n


# generated by oj-template v4.7.2 (https://github.com/online-judge-tools/template-generator)
def main():
N, K = map(int, input().split())
a = solve(N, K)
print(a)


if __name__ == '__main__':
main()
1 change: 1 addition & 0 deletions examples/data/loop_mod_uta8a.1.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
100 3
1 change: 1 addition & 0 deletions examples/data/loop_mod_uta8a.1.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
1 change: 1 addition & 0 deletions examples/data/loop_mod_uta8a.2.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
15 0
1 change: 1 addition & 0 deletions examples/data/loop_mod_uta8a.2.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
15
14 changes: 14 additions & 0 deletions examples/loop_mod_uta8a.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# See https://github.com/kmyk/Jikka/issues/173

def solve(n: int, k: int) -> int:
for _ in range(k):
n = n % 3
return n

def main() -> None:
n, k = map(int, input().split())
ans = solve(n, k)
print(ans)

if __name__ == '__main__':
main()
2 changes: 1 addition & 1 deletion scripts/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ isort --check-only --diff scripts/*.py examples/data/*.py \
yapf --version \
|| { echo HINT: Please install yapf with running '$ pip3 install -r scripts/requirements.txt'; false; }
yapf --diff '--style={ COLUMN_LIMIT: 9999 }' scripts/*.py examples/data/*.py \
|| { echo HINT: Please run 'yapf --in-place '\''--style={ COLUMN_LIMIT: 9999 }'\'' scripts/*.py examples/data/*.py'; false; }
|| { echo HINT: Please run '$ yapf --in-place '\''--style={ COLUMN_LIMIT: 9999 }'\'' scripts/*.py examples/data/*.py'; false; }
mypy scripts/*.py examples/data/*.py

# YAML
Expand Down
11 changes: 7 additions & 4 deletions src/Jikka/Core/Language/ArithmeticExpr.hs
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,13 @@ makeVectorFromArithmeticExpr xs es = runST $ do
let indices = V.imap (\i x -> map (i,) (findIndices (x `isFreeVar`) (productExprList e))) xs
case concat (V.toList indices) of
[] -> lift $ modifySTRef c (plusArithmeticExpr (arithmeticalExprFromProductExpr e))
[(i, j)] -> do
let e' = e {productExprList = take j (productExprList e) ++ drop (j + 1) (productExprList e)}
lift $ MV.modify f (plusArithmeticExpr (arithmeticalExprFromProductExpr e')) i
_ -> MaybeT $ return Nothing
[(i, j)] ->
if productExprList e !! j == Var (xs V.! i)
then do
let e' = e {productExprList = take j (productExprList e) ++ drop (j + 1) (productExprList e)}
lift $ MV.modify f (plusArithmeticExpr (arithmeticalExprFromProductExpr e')) i -- k x_i
else MaybeT $ return Nothing -- e.g. f(x_i)
_ -> MaybeT $ return Nothing -- e.g. x_1 x_2
f <- V.freeze f
c <- lift $ readSTRef c
return (V.map normalizeArithmeticExpr f, normalizeArithmeticExpr c)
Expand Down
5 changes: 5 additions & 0 deletions test/Jikka/Core/Language/ArithmeticExprSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ spec = do
let f = V.fromList [parseArithmeticExpr (LitInt' 2), parseArithmeticExpr (LitInt' 3)]
let c = parseArithmeticExpr (LitInt' (-10))
makeVectorFromArithmeticExpr xs e `shouldBe` Just (f, c)
it "fails with modulo" $ do
-- See https://github.com/kmyk/Jikka/issues/173
let xs = V.singleton "x"
let e = parseArithmeticExpr (FloorMod' (Var "x") (LitInt' 3))
makeVectorFromArithmeticExpr xs e `shouldBe` Nothing
describe "normalizeArithmeticExpr" $ do
it "works" $ do
let e = Plus' (LitInt' 2) (Plus' (Var "a") (LitInt' (-2)))
Expand Down