Submission #444849

# Submission time Handle Problem Language Result Execution time Memory
444849 2021-07-15T14:54:22 Z blue Lamps (JOI19_lamps) C++17
0 / 100
1000 ms 4872 KB
#include <iostream>
#include <vector>
using namespace std;

int op_res(int a, int b){return vector<int>{0,1,-a}[b];}

vector<int> ops[10];

int ops_res(int a, int b)
{
    for(int x: ops[b]) a = op_res(a, x);
    return a;
}

int cost(int ops1, int ops2)
{
    int ans = ops[ops2].size();

    int reducevalue = 0;
    if(ops[ops1] == ops[ops2]) reducevalue = ops[ops2].size();
    else
    {
        for(int x: ops[ops1])
            for(int y: ops[ops2])
                if(x == y)
                    reducevalue = 1;
    }

    return ans - reducevalue;
}

const long long INF = 1'000'000'000LL;

long long* dp1;
long long* dp2;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ops[0] = vector<int>{};
    ops[1] = vector<int>{0};
    ops[2] = vector<int>{1};
    ops[3] = vector<int>{2};
    ops[4] = vector<int>{0, 1};
    ops[5] = vector<int>{0, 2};
    ops[6] = vector<int>{1, 0};
    ops[7] = vector<int>{1, 2};
    ops[8] = vector<int>{2, 0};
    ops[9] = vector<int>{2, 1};

    // for(int i = 0; i <= 9; i++)
    //     for(int j = 0; j <= 9; j++)
    //     {
    //         for(int x: ops[i]) cerr << s[x] << ' ';
    //         cerr << "-> ";
    //         for(int y: ops[j]) cerr << s[y] << ' ';
    //         cerr << ": ";
    //         cerr << cost(i, j) << '\n';
    //     }

    int N;
    cin >> N;

    string A;
    cin >> A;
    A = " " + A;

    string B;
    cin >> B;

    B = " " + B;

    dp1 = new long long[10];
    dp2 = new long long[10];


    dp2[0] = 0;
    for(int o = 1; o < 10; o++) dp2[o] = INF;

    for(int i = 1; i <= N; i++)
    {
        swap(dp1, dp2);
        for(int o2 = 0; o2 < 10; o2++)
        {
            if(ops_res(A[i] - '0', o2) != (B[i] - '0'))
            {
                dp2[o2] = INF;
            }
            else
            {
                dp2[o2] = INF;
                for(int o1 = 0; o1 < 10; o1++)
                {
                    dp2[o2] = min(dp2[o2], dp1[o1] + cost(o1, o2));
                }
            }
        }
    }

    long long ans = INF;
    for(int o = 0; o < 10; o++)
        ans = min(ans, dp2[o]);

    cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 312 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Execution timed out 1058 ms 4872 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -