Releases: kmyk-jikka/Jikka
Releases · kmyk-jikka/Jikka
v5.0.9.0
- The generated C++ stops being functional and becomes natural.
- The restricted Python allows to write
main
function and uses it to analyze input/output format.
Input:
# https://atcoder.jp/contests/dp/tasks/dp_a
from typing import *
def solve(n: int, h: List[int]) -> int:
assert 2 <= n <= 10 ** 5
assert len(h) == n
assert all(1 <= h_i <= 10 ** 4 for h_i in h)
dp = [-1 for _ in range(n)]
dp[0] = 0
dp[1] = abs(h[1] - h[0])
for i in range(2, n):
dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]))
return dp[n - 1]
def main() -> None:
n = int(input())
h = list(map(int, input().split()))
assert len(h) == n
ans = solve(n, h)
print(ans)
if __name__ == '__main__':
main()
Output (https://atcoder.jp/contests/dp/submissions/24221651):
#include "jikka/all.hpp"
#include <algorithm>
#include <cstdint>
#include <functional>
#include <iostream>
#include <numeric>
#include <string>
#include <tuple>
#include <vector>
int64_t solve(int64_t n_0, std::vector<int64_t> h_1) {
int64_t x6;
if (n_0 + -1 == 0) {
x6 = 0;
} else {
std::vector<std::array<int64_t, 2>> x2 =
std::vector<std::array<int64_t, 2>>(n_0 + -2 + 1);
x2[0] = jikka::make_array<int64_t>(
0, std::max<int64_t>(-h_1[0] + h_1[1], h_1[0] + -h_1[1]));
for (int32_t i3 = 0; i3 < int32_t(n_0 + -2); ++i3) {
x2[(i3 + 1)] = jikka::make_array<int64_t>(
x2[i3][1],
std::min<int64_t>(
x2[i3][1] + std::max<int64_t>(-h_1[(i3 + 1)] + h_1[(i3 + 2)],
h_1[(i3 + 1)] + -h_1[(i3 + 2)]),
x2[i3][0] + std::max<int64_t>(-h_1[i3] + h_1[(i3 + 2)],
h_1[i3] + -h_1[(i3 + 2)])));
}
x6 = x2[(n_0 + -2)][1];
}
return x6;
}
int main() {
int64_t n_7 = -1;
std::cin >> n_7;
std::vector<int64_t> h_8 = std::vector<int64_t>(n_7, -1);
for (int32_t i9 = 0; i9 < n_7; ++i9) {
std::cin >> h_8[i9];
}
auto ans_10 = solve(n_7, h_8);
std::cout << ans_10 << ' ';
std::cout << '\n' << ' ';
}
v5.0.8.0
Some optimizers are added.
Now it can use cumulative sums.
Input:
# https://judge.yosupo.jp/problem/static_range_sum
from typing import *
def solve(n: int, q: int, a: List[int], l: List[int], r: List[int]) -> List[int]:
ans = [-1 for _ in range(q)]
for i in range(q):
ans[i] = sum(a[l[i]:r[i]])
return ans
Output:
std::vector<int64_t> solve(int64_t n_1653, int64_t q_1654,
std::vector<int64_t> a_1655,
std::vector<int64_t> l_1656,
std::vector<int64_t> r_1657) {
std::vector<int64_t> x1658 = jikka::scanl<int64_t, int64_t>(
[=](int64_t b1659) -> std::function<int64_t(int64_t)> {
return [=](int64_t b1660) -> int64_t { return b1659 + b1660; };
},
0, a_1655);
return jikka::fmap<int64_t, int64_t>(
[=](int64_t b1661) -> int64_t {
return x1658[(r_1657[b1661] + (-l_1656[b1661] + l_1656[b1661]))] +
-x1658[l_1656[b1661]];
},
jikka::range1(q_1654));
}
v5.0.7.0
v5.0.6.0
Error reporting and error recovery are improved.
Input:
def solve(n: int) -> bool:
a = n + True # err
b = 2 * n
return b # err
Output:
Type Error (line 2 column 13) (user's mistake?): Jikka.RestrictedPython.Convert.TypeInfer: failed to solve type equations: failed to unify type int and type bool: type int is not type bool
1 |def solve(n: int) -> bool:
2 | a = n + True # err
^^^^
3 | b = 2 * n
Type Error (line 4 column 12) (user's mistake?): Jikka.RestrictedPython.Convert.TypeInfer: failed to solve type equations: failed to unify type bool and type int: type bool is not type int
3 | b = 2 * n
4 | return b # err
^
contributions:
- @Koki-Yamaguchi fixed build on macOS (#28)
v5.0.5.0
Some optimizations are implemented.
Now it can convert a O(N) Python code for fibonacci to O(log N) C++ code.
Input, O(N):
def f(n: int) -> int:
a = 0
b = 1
for _ in range(n):
c = a + b
a = b
b = c
return a
def solve(n: int) -> int:
return f(n) % 1000000007
Output, O(log N):
#include "jikka/all.hpp"
#include <algorithm>
#include <cstdint>
#include <functional>
#include <iostream>
#include <numeric>
#include <string>
#include <tuple>
#include <vector>
int64_t solve(int64_t n_317) {
return jikka::modmatap<2, 2>(
jikka::modmatpow<2>(jikka::make_array<std::array<int64_t, 2>>(
jikka::make_array<int64_t>(1, 1),
jikka::make_array<int64_t>(1, 0)),
n_317, 1000000007),
jikka::make_array<int64_t>(1, 0), 1000000007)[1];
}
int main() {
int64_t x318;
std::cin >> x318;
int64_t x319 = solve(x318);
std::cout << x319;
std::cout << '\n';
}