답안 #796670

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
796670 2023-07-28T15:30:22 Z vjudge1 Lamps (JOI19_lamps) C++17
100 / 100
104 ms 51420 KB

// Author : حسن

#include <bits/stdc++.h>



using namespace std;

#define TL ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define rall(s) s.rbegin(),s.rend()
#define all(s) s.begin(),s.end()
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ld long double
#define YES cout<<"YES\n"
#define Yes cout<<"Yes\n"
#define yes cout<<"yes\n"
#define NO cout<<"NO\n"
#define No cout<<"No\n"
#define no cout<<"no\n"


const int N = 1e6 + 9 , mod = 1e9 + 7;
ll c[N] = {} , dp[N] = {} , a[N] = {}, b[N] = {} , d[N][3][2];

void solve(){
    ll q , i , j , m , n , z , s  = 0, f, l , r , k , x , y , mn  = 1e18 , mx = 0;
    cin>>n;
    string a , b;
    cin>>a>>b;
    for(i = 0;i <= n; i++)
        for(j = 0; j < 3; j++)
            for(k = 0; k < 2; k++)
                d[i][j][k] = 1e9;
    d[0][0][0] = 0;
    for(i = 1; i <= n; i++){
        for(x = 0; x < 3; x++){
            for(y = 0; y < 2; y++){
                d[i][x][y] = min(d[i][x][y] , d[i - 1][x][y]);
                d[i][0][y] = min(d[i][0][y] , d[i - 1][x][y]);
                d[i][x][0] = min(d[i][x][0] , d[i - 1][x][y]);
                d[i][0][0] = min(d[i][0][0] , d[i - 1][x][y]);
                if(x == 0){
                    d[i][1][y] = min(d[i][1][y] , d[i - 1][x][y] + 1);
                    d[i][2][y] = min(d[i][2][y] , d[i - 1][x][y] + 1);
                }
                if(x == 0 && y == 0){
                    d[i][1][1] = min(d[i][1][1] , d[i - 1][x][y] + 2);
                    d[i][2][1] = min(d[i][2][1] , d[i - 1][x][y] + 2);
                }
                if(y == 0){
                    d[i][x][1] = min(d[i][x][1] , d[i - 1][x][y] + 1);
                }
            }
        }
        for(x = 0;x < 3; x++){
            for(y = 0;y < 2; y++){
                l = a[i - 1] - '0';
                r = b[i - 1] - '0';
                if(x == 1) l = 1;
                if(x == 2) l = 0;
                if(y == 1) l = 1 - l;
                if(l != r)
                    d[i][x][y]= 1e9;
            }
        }
    }
    for(i = 0;i < 3; i++)
        for(j = 0; j < 2; j++)
        mn = min(mn , d[n][i][j]);
    cout<<mn;
}

int main(){
    /*
     TL;
     #ifndef ONLINE_JUDGE
     freopen("input.txt", "r", stdin);
     freopen("output.txt", "w", stdout);
     #endif*/

int t = 1;
//cin>>t;

while(t--)
     {
     solve();
     }

}
// Author : حسن

Compilation message

lamp.cpp: In function 'void solve()':
lamp.cpp:31:8: warning: unused variable 'q' [-Wunused-variable]
   31 |     ll q , i , j , m , n , z , s  = 0, f, l , r , k , x , y , mn  = 1e18 , mx = 0;
      |        ^
lamp.cpp:31:20: warning: unused variable 'm' [-Wunused-variable]
   31 |     ll q , i , j , m , n , z , s  = 0, f, l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                    ^
lamp.cpp:31:28: warning: unused variable 'z' [-Wunused-variable]
   31 |     ll q , i , j , m , n , z , s  = 0, f, l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                            ^
lamp.cpp:31:32: warning: unused variable 's' [-Wunused-variable]
   31 |     ll q , i , j , m , n , z , s  = 0, f, l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                                ^
lamp.cpp:31:40: warning: unused variable 'f' [-Wunused-variable]
   31 |     ll q , i , j , m , n , z , s  = 0, f, l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                                        ^
lamp.cpp:31:76: warning: unused variable 'mx' [-Wunused-variable]
   31 |     ll q , i , j , m , n , z , s  = 0, f, l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                                                                            ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 304 KB Output is correct
42 Correct 1 ms 304 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 308 KB Output is correct
48 Correct 2 ms 340 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 1 ms 308 KB Output is correct
54 Correct 1 ms 312 KB Output is correct
55 Correct 1 ms 340 KB Output is correct
56 Correct 1 ms 304 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 82 ms 49320 KB Output is correct
8 Correct 85 ms 49228 KB Output is correct
9 Correct 84 ms 49356 KB Output is correct
10 Correct 84 ms 49364 KB Output is correct
11 Correct 83 ms 49260 KB Output is correct
12 Correct 84 ms 49360 KB Output is correct
13 Correct 83 ms 49364 KB Output is correct
14 Correct 83 ms 49380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 304 KB Output is correct
42 Correct 1 ms 304 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 308 KB Output is correct
48 Correct 2 ms 340 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 1 ms 308 KB Output is correct
54 Correct 1 ms 312 KB Output is correct
55 Correct 1 ms 340 KB Output is correct
56 Correct 1 ms 304 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 0 ms 212 KB Output is correct
61 Correct 1 ms 212 KB Output is correct
62 Correct 0 ms 212 KB Output is correct
63 Correct 0 ms 212 KB Output is correct
64 Correct 0 ms 212 KB Output is correct
65 Correct 82 ms 49320 KB Output is correct
66 Correct 85 ms 49228 KB Output is correct
67 Correct 84 ms 49356 KB Output is correct
68 Correct 84 ms 49364 KB Output is correct
69 Correct 83 ms 49260 KB Output is correct
70 Correct 84 ms 49360 KB Output is correct
71 Correct 83 ms 49364 KB Output is correct
72 Correct 83 ms 49380 KB Output is correct
73 Correct 86 ms 51284 KB Output is correct
74 Correct 81 ms 51308 KB Output is correct
75 Correct 84 ms 51212 KB Output is correct
76 Correct 84 ms 51320 KB Output is correct
77 Correct 85 ms 51220 KB Output is correct
78 Correct 88 ms 51420 KB Output is correct
79 Correct 80 ms 51320 KB Output is correct
80 Correct 84 ms 51260 KB Output is correct
81 Correct 83 ms 51264 KB Output is correct
82 Correct 82 ms 51296 KB Output is correct
83 Correct 86 ms 51312 KB Output is correct
84 Correct 85 ms 51316 KB Output is correct
85 Correct 98 ms 51312 KB Output is correct
86 Correct 84 ms 51316 KB Output is correct
87 Correct 94 ms 51260 KB Output is correct
88 Correct 83 ms 51312 KB Output is correct
89 Correct 95 ms 51312 KB Output is correct
90 Correct 84 ms 51316 KB Output is correct
91 Correct 86 ms 51324 KB Output is correct
92 Correct 86 ms 51216 KB Output is correct
93 Correct 84 ms 51316 KB Output is correct
94 Correct 85 ms 51200 KB Output is correct
95 Correct 83 ms 51316 KB Output is correct
96 Correct 85 ms 51312 KB Output is correct
97 Correct 95 ms 51236 KB Output is correct
98 Correct 84 ms 51332 KB Output is correct
99 Correct 87 ms 51312 KB Output is correct
100 Correct 104 ms 51320 KB Output is correct
101 Correct 84 ms 51316 KB Output is correct
102 Correct 85 ms 51316 KB Output is correct