답안 #239078

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
239078 2020-06-14T10:21:55 Z Dremix10 Lamps (JOI19_lamps) C++17
100 / 100
133 ms 96588 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define F first
#define S second
#define endl '\n'
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define maxp 22
#define EPS (ld)(1e-18)
#define mod (int)(1e9+7)
#define N (int)(1e6+1)

string a,b;
int n;
int dp[N][6];
bool v[N][6];

/// operation 0 -> no operation
/// operation 1 -> set 1
/// operation 2 -> set 0
/// operation 3 -> toggled
/// operation 4 -> set 1 and toggled
/// operation 5 -> set 0 and toggled

int solve(int x, int state){
    if(x==0)
        return 0;
    if(v[x][state])
        return dp[x][state];

    v[x][state]=1;
    int ans=mod;

    if(state==0){
        if(a[x-1]==b[x-1])
            ans=min(ans,solve(x-1,0));
        else
            ans=min(ans,solve(x-1,3)+1);

        if(b[x-1]=='1'){
            ans=min(ans,solve(x-1,1)+1);
            ans=min(ans,solve(x-1,5)+2);
        }
        else{
            ans=min(ans,solve(x-1,2)+1);
            ans=min(ans,solve(x-1,4)+2);
        }
    }

    else if(state==1){
        if(a[x-1]==b[x-1])
            ans=min(ans,solve(x-1,0));
        else
            ans=min(ans,solve(x-1,3)+1);

        if(b[x-1]=='1'){
            ans=min(ans,solve(x-1,1));
            ans=min(ans,solve(x-1,5)+2);
        }
        else{
            ans=min(ans,solve(x-1,2)+1);
            ans=min(ans,solve(x-1,4)+1);
        }
    }

    else if(state==2){
        if(a[x-1]==b[x-1])
            ans=min(ans,solve(x-1,0));
        else
            ans=min(ans,solve(x-1,3)+1);

        if(b[x-1]=='1'){
            ans=min(ans,solve(x-1,1)+1);
            ans=min(ans,solve(x-1,5)+1);
        }
        else{
            ans=min(ans,solve(x-1,2));
            ans=min(ans,solve(x-1,4)+2);
        }
    }

    else if(state==3){
        if(a[x-1]==b[x-1])
            ans=min(ans,solve(x-1,0));
        else
            ans=min(ans,solve(x-1,3));

        if(b[x-1]=='1'){
            ans=min(ans,solve(x-1,1)+1);
            ans=min(ans,solve(x-1,5)+1);
        }
        else{
            ans=min(ans,solve(x-1,2)+1);
            ans=min(ans,solve(x-1,4)+1);
        }
    }

    else if(state==4){
        if(a[x-1]==b[x-1])
            ans=min(ans,solve(x-1,0));
        else
            ans=min(ans,solve(x-1,3));

        if(b[x-1]=='1'){
            ans=min(ans,solve(x-1,1));
            ans=min(ans,solve(x-1,5)+1);
        }
        else{
            ans=min(ans,solve(x-1,2)+1);
            ans=min(ans,solve(x-1,4));
        }
    }
    else{
        if(a[x-1]==b[x-1])
            ans=min(ans,solve(x-1,0));
        else
            ans=min(ans,solve(x-1,3));

        if(b[x-1]=='1'){
            ans=min(ans,solve(x-1,1)+1);
            ans=min(ans,solve(x-1,5));
        }
        else{
            ans=min(ans,solve(x-1,2));
            ans=min(ans,solve(x-1,4)+2);
        }
    }
    dp[x][state]=ans;
    return ans;
}

int main (){
fastio;

cin>>n;

cin>>a>>b;
int i,j;
for(i=1;i<=n;i++)
    for(j=0;j<6;j++)
        dp[i][j]=-1;
cout<<solve(n,0)<<endl;

}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 4 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 4 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 4 ms 384 KB Output is correct
26 Correct 4 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 4 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 4 ms 384 KB Output is correct
33 Correct 4 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 4 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 4 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 4 ms 384 KB Output is correct
26 Correct 4 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 4 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 4 ms 384 KB Output is correct
33 Correct 4 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 512 KB Output is correct
36 Correct 5 ms 512 KB Output is correct
37 Correct 5 ms 512 KB Output is correct
38 Correct 5 ms 512 KB Output is correct
39 Correct 5 ms 512 KB Output is correct
40 Correct 5 ms 640 KB Output is correct
41 Correct 5 ms 512 KB Output is correct
42 Correct 5 ms 512 KB Output is correct
43 Correct 5 ms 512 KB Output is correct
44 Correct 5 ms 512 KB Output is correct
45 Correct 5 ms 512 KB Output is correct
46 Correct 5 ms 512 KB Output is correct
47 Correct 5 ms 512 KB Output is correct
48 Correct 5 ms 512 KB Output is correct
49 Correct 5 ms 512 KB Output is correct
50 Correct 5 ms 512 KB Output is correct
51 Correct 5 ms 512 KB Output is correct
52 Correct 5 ms 512 KB Output is correct
53 Correct 5 ms 512 KB Output is correct
54 Correct 5 ms 512 KB Output is correct
55 Correct 5 ms 512 KB Output is correct
56 Correct 5 ms 512 KB Output is correct
57 Correct 5 ms 512 KB Output is correct
58 Correct 5 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 107 ms 96352 KB Output is correct
8 Correct 108 ms 96420 KB Output is correct
9 Correct 106 ms 96452 KB Output is correct
10 Correct 106 ms 96324 KB Output is correct
11 Correct 110 ms 96332 KB Output is correct
12 Correct 110 ms 96336 KB Output is correct
13 Correct 107 ms 96324 KB Output is correct
14 Correct 114 ms 96328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 4 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 4 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 4 ms 384 KB Output is correct
26 Correct 4 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 4 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 4 ms 384 KB Output is correct
33 Correct 4 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 512 KB Output is correct
36 Correct 5 ms 512 KB Output is correct
37 Correct 5 ms 512 KB Output is correct
38 Correct 5 ms 512 KB Output is correct
39 Correct 5 ms 512 KB Output is correct
40 Correct 5 ms 640 KB Output is correct
41 Correct 5 ms 512 KB Output is correct
42 Correct 5 ms 512 KB Output is correct
43 Correct 5 ms 512 KB Output is correct
44 Correct 5 ms 512 KB Output is correct
45 Correct 5 ms 512 KB Output is correct
46 Correct 5 ms 512 KB Output is correct
47 Correct 5 ms 512 KB Output is correct
48 Correct 5 ms 512 KB Output is correct
49 Correct 5 ms 512 KB Output is correct
50 Correct 5 ms 512 KB Output is correct
51 Correct 5 ms 512 KB Output is correct
52 Correct 5 ms 512 KB Output is correct
53 Correct 5 ms 512 KB Output is correct
54 Correct 5 ms 512 KB Output is correct
55 Correct 5 ms 512 KB Output is correct
56 Correct 5 ms 512 KB Output is correct
57 Correct 5 ms 512 KB Output is correct
58 Correct 5 ms 512 KB Output is correct
59 Correct 5 ms 384 KB Output is correct
60 Correct 5 ms 384 KB Output is correct
61 Correct 5 ms 384 KB Output is correct
62 Correct 5 ms 384 KB Output is correct
63 Correct 4 ms 384 KB Output is correct
64 Correct 5 ms 384 KB Output is correct
65 Correct 107 ms 96352 KB Output is correct
66 Correct 108 ms 96420 KB Output is correct
67 Correct 106 ms 96452 KB Output is correct
68 Correct 106 ms 96324 KB Output is correct
69 Correct 110 ms 96332 KB Output is correct
70 Correct 110 ms 96336 KB Output is correct
71 Correct 107 ms 96324 KB Output is correct
72 Correct 114 ms 96328 KB Output is correct
73 Correct 106 ms 96324 KB Output is correct
74 Correct 115 ms 96332 KB Output is correct
75 Correct 110 ms 96588 KB Output is correct
76 Correct 106 ms 96328 KB Output is correct
77 Correct 111 ms 96328 KB Output is correct
78 Correct 107 ms 96328 KB Output is correct
79 Correct 108 ms 96328 KB Output is correct
80 Correct 108 ms 96328 KB Output is correct
81 Correct 111 ms 96460 KB Output is correct
82 Correct 108 ms 96328 KB Output is correct
83 Correct 121 ms 96328 KB Output is correct
84 Correct 122 ms 96332 KB Output is correct
85 Correct 122 ms 96328 KB Output is correct
86 Correct 119 ms 96332 KB Output is correct
87 Correct 122 ms 96452 KB Output is correct
88 Correct 121 ms 96332 KB Output is correct
89 Correct 124 ms 96328 KB Output is correct
90 Correct 127 ms 96328 KB Output is correct
91 Correct 123 ms 96332 KB Output is correct
92 Correct 125 ms 96332 KB Output is correct
93 Correct 125 ms 96328 KB Output is correct
94 Correct 126 ms 96332 KB Output is correct
95 Correct 130 ms 96332 KB Output is correct
96 Correct 125 ms 96412 KB Output is correct
97 Correct 126 ms 96456 KB Output is correct
98 Correct 127 ms 96332 KB Output is correct
99 Correct 125 ms 96468 KB Output is correct
100 Correct 133 ms 96324 KB Output is correct
101 Correct 129 ms 96456 KB Output is correct
102 Correct 125 ms 96332 KB Output is correct