답안 #105864

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
105864 2019-04-15T11:16:13 Z Alexa2001 Lamps (JOI19_lamps) C++17
6 / 100
1000 ms 22500 KB
#include <bits/stdc++.h>

using namespace std;

const int Nmax = 1e6 + 5;

int a[Nmax], b[Nmax], a0[Nmax], b0[Nmax], ones[Nmax], dp[Nmax];
int i, j, n;

int nr_ones(int x, int y)
{
    return ones[y] - ones[x-1];
}

int main()
{
  //  freopen("input", "r", stdin);
    cin.sync_with_stdio(false);

    cin >> n;
    string A, B;
    cin >> A >> B;

    for(i=1; i<=n; ++i)
        a0[i] = A[i-1] - '0', b0[i] = B[i-1] - '0';

    for(i=1; i<=n+1; ++i)
        a[i] = a0[i-1] ^ a0[i], b[i] = b0[i-1] ^ b0[i];

    for(i=1; i<=n+1; ++i) ones[i] = ones[i-1] + b[i];

    for(i=1; i<=n+1; ++i)
    {
        dp[i] = dp[i-1] + (a[i] ^ b[i]);

        for(j=1; j<i; ++j) /// flip cu schimbare j...i
            dp[i] = min(dp[i], dp[j-1] + 2 + (a[i] ^ b[i] ^ 1) + (a[j] ^ b[j] ^ 1) + nr_ones(j+1, i-1) );
    }

    cout << (dp[n+1] + 1)/2 << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 3 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 2 ms 412 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 3 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 2 ms 412 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 6 ms 512 KB Output is correct
36 Correct 7 ms 516 KB Output is correct
37 Correct 5 ms 384 KB Output is correct
38 Correct 8 ms 384 KB Output is correct
39 Correct 5 ms 384 KB Output is correct
40 Correct 6 ms 384 KB Output is correct
41 Correct 6 ms 512 KB Output is correct
42 Correct 6 ms 384 KB Output is correct
43 Incorrect 7 ms 640 KB Output isn't correct
44 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Execution timed out 1084 ms 22500 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 3 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 2 ms 412 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 6 ms 512 KB Output is correct
36 Correct 7 ms 516 KB Output is correct
37 Correct 5 ms 384 KB Output is correct
38 Correct 8 ms 384 KB Output is correct
39 Correct 5 ms 384 KB Output is correct
40 Correct 6 ms 384 KB Output is correct
41 Correct 6 ms 512 KB Output is correct
42 Correct 6 ms 384 KB Output is correct
43 Incorrect 7 ms 640 KB Output isn't correct
44 Halted 0 ms 0 KB -