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

fix(cxx): Fix a bug of MoveSemantics #168

Merged
merged 12 commits into from
Aug 13, 2021
Merged

fix(cxx): Fix a bug of MoveSemantics #168

merged 12 commits into from
Aug 13, 2021

Conversation

kmyk
Copy link
Collaborator

@kmyk kmyk commented Aug 6, 2021

#154 のトップのコメント (#154 (comment)) の変換は直った。でも #153 のフィボナッチ数列のコード + mod はまだ動かない
cc @riantkb

@kmyk
Copy link
Collaborator Author

kmyk commented Aug 7, 2021

別のバグが埋まってテストが落ちてる……

@kmyk
Copy link
Collaborator Author

kmyk commented Aug 7, 2021

こんどは仕事しなさすぎて計算量が上がって TLE してる

input: examples/dp_b.py

# https://atcoder.jp/contests/dp/tasks/dp_b
from typing import *

INF = 10 ** 18

def solve(n: int, k: int, h: List[int]) -> int:
    assert 2 <= n <= 10 ** 5
    assert 1 <= k <= 100
    assert len(h) == n
    assert all(1 <= h_i <= 10 ** 4 for h_i in h)

    dp = [INF for _ in range(n)]
    dp[0] = 0
    for i in range(1, n):
        for j in range(max(0, i - k), i):
            dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]))
    return dp[n - 1]

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

if __name__ == '__main__':
    main()

output:

int64_t solve(int64_t n_0, int64_t k_1, std::vector<int64_t> h_2) {
    assert (- n_0 + 2 <= 0 and n_0 - 100000 <= 0);
    assert (- k_1 + 1 <= 0 and k_1 - 100 <= 0);
    assert (- n_0 + int64_t(h_2.size()) == 0);
    std::vector<bool> x3(h_2.size());
    for (int32_t i4 = 0; i4 < int32_t(h_2.size()); ++ i4) {
        x3[i4] = - h_2[i4] + 1 <= 0 and h_2[i4] - 10000 <= 0;
    }
    bool x6 = std::find(x3.begin(), x3.end(), false) == x3.end();
    assert (x6);
    std::vector<int64_t> x7(n_0, 1000000000000000000ll);
    x7[0] = 0;
    for (int32_t x10 = 0; x10 < n_0 - 1; ++ x10) {
        for (int32_t x14 = 0; x14 < x10 - std::max<int64_t>(0, x10 - k_1 + 1) + 1; ++ x14) {
            std::vector<int64_t> x17 = x7;
            x17[x10 + 1] = std::min<int64_t>(x7[x10 + 1], std::max<int64_t>(h_2[x10 + 1] - h_2[x14 + std::max<int64_t>(0, x10 - k_1 + 1)], - h_2[x10 + 1] + h_2[x14 + std::max<int64_t>(0, x10 - k_1 + 1)]) + x7[x14 + std::max<int64_t>(0, x10 - k_1 + 1)]);
            x7 = x17;
        }
    }
    return x7[n_0 - 1];
}

@kmyk
Copy link
Collaborator Author

kmyk commented Aug 7, 2021

たとえば

vector<int> func(vector<int> a) {
    for (int i = 0; i < n - 1; ++ i) {
        vector<int> b = a;
        b[i + 1] = a[i];
        a = b;
    }
    return a;
}

vector<int> func(vector<int> a) {
    for (int i = 0; i < n - 1; ++ i) {
        a[i + 1] = a[i];
    }
    return a;
}

に変換しないとだめなのだけど、これ無理じゃない?
core から C++ への変換のときに情報が落ちてしまってて、その状態で添字の解析をやるのはしんどすぎるし、ある程度はやれたとしても不可能ケースが残ってしまう。
UnpackTuples.hs や MoveSemantics.hs の中身をすべて ToCore.hs に埋め込んで、core から C++ への変換のときにすべてを同時に最適にやるしかなさそう

@kmyk kmyk changed the title fix(cxx): Fix a bug of MoveSemantics WIP: fix(cxx): Fix a bug of MoveSemantics Aug 7, 2021
@kmyk kmyk linked an issue Aug 13, 2021 that may be closed by this pull request
@kmyk kmyk changed the title WIP: fix(cxx): Fix a bug of MoveSemantics fix(cxx): Fix a bug of MoveSemantics Aug 13, 2021
@kmyk kmyk linked an issue Aug 13, 2021 that may be closed by this pull request
@kmyk kmyk merged commit c206863 into master Aug 13, 2021
@kmyk kmyk deleted the fix-154 branch August 13, 2021 03:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Haskell から C++ への変換時のロスをなくす copy を move に直す際にやりすぎてる
1 participant