Submission #937768

# Submission time Handle Problem Language Result Execution time Memory
937768 2024-03-04T12:49:52 Z wojciech_domin2 Lamps (JOI19_lamps) C++14
100 / 100
596 ms 36140 KB
#include <bits/stdc++.h>
#define pb push_back
#define ins insert
#define fi first
#define se second
#define debug(x) cout<<#x<<" = "<<x<<"\n";

using namespace std;
using ll = long long;
using ld = long double;

template <typename H, typename T> 
ostream& operator<<(ostream& os, pair<H, T> m){
	return os <<"("<< m.fi<<", "<<m.se<<")";
}
 
template <typename H> 
ostream& operator<<(ostream& os, vector<H> V){
	os<<"{";
	for(int i=0; i<V.size(); i++){
		if(i)os<<" ";
		os<<V[i];
	}
	os<<"}";
	return os;
}

const int MAX_N = 1000020;
const int INF = 21372137;
char A[MAX_N];
char B[MAX_N];
int dp[MAX_N][2][4];

bitset<MAX_N> a,b;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin>>N;
    for(int i = 1; i <= N; i++){
        cin>>A[i];
    }
    for(int i = 1; i <= N; i++){
        cin>>B[i];
    }
 
    for(int i =1; i <= N; i++){
       
        a[i] = int(A[i]^'0');
        b[i] = int(B[i]^'0');
 
    }
    for(int j = 0; j < MAX_N; j++){
        for(int i = 0; i < 4; i++){
            dp[j][0][i] = INF;
            dp[j][1][i] = INF;
        }
    }
    dp[0][0][0] = 0;
    for(int i = 1; i <= N; i++){
        for(int k = 0; k < 2; k++){
            for(int j = 0; j < 4; j++){
                vector<pair<int,int> > cennik;
                cennik.pb({0,0});
                cennik.pb({1,1});
                cennik.pb({2,1});
                cennik.pb({j,0});
                for(auto t : cennik){
                    dp[i][k][t.fi] = min(dp[i-1][0][j] + k + t.se, dp[i][k][t.fi]);
                    dp[i][k][t.fi] = min(dp[i-1][1][j] + 0 + t.se, dp[i][k][t.fi]);
                }
            }
            
        }
        for(int k = 0; k < 2; k++){
        for(int j = 0; j < 4; j++){       
            int kwiatek = j;
            int wart_a = int(A[i]^'0');
            int wart_b = int(B[i]^'0');
            bool ok = false;
            if(kwiatek == 0){
                if((wart_a^k)==wart_b) ok = true;
            }else{
                kwiatek--;
                kwiatek^=k;
                if(wart_b == kwiatek) ok = true;
            }
            if(!ok){
                dp[i][k][j] = INF;
            } 
        }
        }
    }
    int odp = INF;
    for(int i = 0; i < 4; i++){
        odp = min(odp,dp[N][0][i]);
        odp = min(odp,dp[N][1][i]);
    }

    cout<<odp<<"\n";
   


    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 33112 KB Output is correct
2 Correct 8 ms 33116 KB Output is correct
3 Correct 6 ms 33116 KB Output is correct
4 Correct 6 ms 33116 KB Output is correct
5 Correct 9 ms 33116 KB Output is correct
6 Correct 6 ms 33112 KB Output is correct
7 Correct 6 ms 33116 KB Output is correct
8 Correct 6 ms 33116 KB Output is correct
9 Correct 6 ms 33272 KB Output is correct
10 Correct 6 ms 33232 KB Output is correct
11 Correct 7 ms 33116 KB Output is correct
12 Correct 8 ms 33116 KB Output is correct
13 Correct 7 ms 33116 KB Output is correct
14 Correct 7 ms 33232 KB Output is correct
15 Correct 6 ms 33296 KB Output is correct
16 Correct 7 ms 33116 KB Output is correct
17 Correct 7 ms 33116 KB Output is correct
18 Correct 7 ms 33292 KB Output is correct
19 Correct 7 ms 33116 KB Output is correct
20 Correct 6 ms 33116 KB Output is correct
21 Correct 7 ms 33252 KB Output is correct
22 Correct 6 ms 33116 KB Output is correct
23 Correct 6 ms 33116 KB Output is correct
24 Correct 6 ms 33116 KB Output is correct
25 Correct 6 ms 33268 KB Output is correct
26 Correct 6 ms 33116 KB Output is correct
27 Correct 6 ms 33116 KB Output is correct
28 Correct 6 ms 33260 KB Output is correct
29 Correct 6 ms 33112 KB Output is correct
30 Correct 6 ms 33112 KB Output is correct
31 Correct 6 ms 33116 KB Output is correct
32 Correct 6 ms 33116 KB Output is correct
33 Correct 7 ms 33116 KB Output is correct
34 Correct 6 ms 33116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 33112 KB Output is correct
2 Correct 8 ms 33116 KB Output is correct
3 Correct 6 ms 33116 KB Output is correct
4 Correct 6 ms 33116 KB Output is correct
5 Correct 9 ms 33116 KB Output is correct
6 Correct 6 ms 33112 KB Output is correct
7 Correct 6 ms 33116 KB Output is correct
8 Correct 6 ms 33116 KB Output is correct
9 Correct 6 ms 33272 KB Output is correct
10 Correct 6 ms 33232 KB Output is correct
11 Correct 7 ms 33116 KB Output is correct
12 Correct 8 ms 33116 KB Output is correct
13 Correct 7 ms 33116 KB Output is correct
14 Correct 7 ms 33232 KB Output is correct
15 Correct 6 ms 33296 KB Output is correct
16 Correct 7 ms 33116 KB Output is correct
17 Correct 7 ms 33116 KB Output is correct
18 Correct 7 ms 33292 KB Output is correct
19 Correct 7 ms 33116 KB Output is correct
20 Correct 6 ms 33116 KB Output is correct
21 Correct 7 ms 33252 KB Output is correct
22 Correct 6 ms 33116 KB Output is correct
23 Correct 6 ms 33116 KB Output is correct
24 Correct 6 ms 33116 KB Output is correct
25 Correct 6 ms 33268 KB Output is correct
26 Correct 6 ms 33116 KB Output is correct
27 Correct 6 ms 33116 KB Output is correct
28 Correct 6 ms 33260 KB Output is correct
29 Correct 6 ms 33112 KB Output is correct
30 Correct 6 ms 33112 KB Output is correct
31 Correct 6 ms 33116 KB Output is correct
32 Correct 6 ms 33116 KB Output is correct
33 Correct 7 ms 33116 KB Output is correct
34 Correct 6 ms 33116 KB Output is correct
35 Correct 8 ms 33264 KB Output is correct
36 Correct 7 ms 33504 KB Output is correct
37 Correct 7 ms 33116 KB Output is correct
38 Correct 8 ms 33116 KB Output is correct
39 Correct 8 ms 33292 KB Output is correct
40 Correct 7 ms 33232 KB Output is correct
41 Correct 8 ms 33116 KB Output is correct
42 Correct 8 ms 33116 KB Output is correct
43 Correct 8 ms 33116 KB Output is correct
44 Correct 8 ms 33116 KB Output is correct
45 Correct 8 ms 33368 KB Output is correct
46 Correct 8 ms 33116 KB Output is correct
47 Correct 7 ms 33116 KB Output is correct
48 Correct 7 ms 33116 KB Output is correct
49 Correct 8 ms 33264 KB Output is correct
50 Correct 8 ms 33236 KB Output is correct
51 Correct 7 ms 33116 KB Output is correct
52 Correct 8 ms 33116 KB Output is correct
53 Correct 7 ms 33116 KB Output is correct
54 Correct 9 ms 33228 KB Output is correct
55 Correct 8 ms 33116 KB Output is correct
56 Correct 8 ms 33116 KB Output is correct
57 Correct 8 ms 33116 KB Output is correct
58 Correct 8 ms 33112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 33112 KB Output is correct
2 Correct 6 ms 33116 KB Output is correct
3 Correct 6 ms 33116 KB Output is correct
4 Correct 7 ms 33112 KB Output is correct
5 Correct 6 ms 33116 KB Output is correct
6 Correct 6 ms 33232 KB Output is correct
7 Correct 533 ms 35704 KB Output is correct
8 Correct 566 ms 35900 KB Output is correct
9 Correct 527 ms 35908 KB Output is correct
10 Correct 526 ms 35900 KB Output is correct
11 Correct 537 ms 35908 KB Output is correct
12 Correct 534 ms 35904 KB Output is correct
13 Correct 549 ms 35900 KB Output is correct
14 Correct 529 ms 35904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 33112 KB Output is correct
2 Correct 8 ms 33116 KB Output is correct
3 Correct 6 ms 33116 KB Output is correct
4 Correct 6 ms 33116 KB Output is correct
5 Correct 9 ms 33116 KB Output is correct
6 Correct 6 ms 33112 KB Output is correct
7 Correct 6 ms 33116 KB Output is correct
8 Correct 6 ms 33116 KB Output is correct
9 Correct 6 ms 33272 KB Output is correct
10 Correct 6 ms 33232 KB Output is correct
11 Correct 7 ms 33116 KB Output is correct
12 Correct 8 ms 33116 KB Output is correct
13 Correct 7 ms 33116 KB Output is correct
14 Correct 7 ms 33232 KB Output is correct
15 Correct 6 ms 33296 KB Output is correct
16 Correct 7 ms 33116 KB Output is correct
17 Correct 7 ms 33116 KB Output is correct
18 Correct 7 ms 33292 KB Output is correct
19 Correct 7 ms 33116 KB Output is correct
20 Correct 6 ms 33116 KB Output is correct
21 Correct 7 ms 33252 KB Output is correct
22 Correct 6 ms 33116 KB Output is correct
23 Correct 6 ms 33116 KB Output is correct
24 Correct 6 ms 33116 KB Output is correct
25 Correct 6 ms 33268 KB Output is correct
26 Correct 6 ms 33116 KB Output is correct
27 Correct 6 ms 33116 KB Output is correct
28 Correct 6 ms 33260 KB Output is correct
29 Correct 6 ms 33112 KB Output is correct
30 Correct 6 ms 33112 KB Output is correct
31 Correct 6 ms 33116 KB Output is correct
32 Correct 6 ms 33116 KB Output is correct
33 Correct 7 ms 33116 KB Output is correct
34 Correct 6 ms 33116 KB Output is correct
35 Correct 8 ms 33264 KB Output is correct
36 Correct 7 ms 33504 KB Output is correct
37 Correct 7 ms 33116 KB Output is correct
38 Correct 8 ms 33116 KB Output is correct
39 Correct 8 ms 33292 KB Output is correct
40 Correct 7 ms 33232 KB Output is correct
41 Correct 8 ms 33116 KB Output is correct
42 Correct 8 ms 33116 KB Output is correct
43 Correct 8 ms 33116 KB Output is correct
44 Correct 8 ms 33116 KB Output is correct
45 Correct 8 ms 33368 KB Output is correct
46 Correct 8 ms 33116 KB Output is correct
47 Correct 7 ms 33116 KB Output is correct
48 Correct 7 ms 33116 KB Output is correct
49 Correct 8 ms 33264 KB Output is correct
50 Correct 8 ms 33236 KB Output is correct
51 Correct 7 ms 33116 KB Output is correct
52 Correct 8 ms 33116 KB Output is correct
53 Correct 7 ms 33116 KB Output is correct
54 Correct 9 ms 33228 KB Output is correct
55 Correct 8 ms 33116 KB Output is correct
56 Correct 8 ms 33116 KB Output is correct
57 Correct 8 ms 33116 KB Output is correct
58 Correct 8 ms 33112 KB Output is correct
59 Correct 6 ms 33112 KB Output is correct
60 Correct 6 ms 33116 KB Output is correct
61 Correct 6 ms 33116 KB Output is correct
62 Correct 7 ms 33112 KB Output is correct
63 Correct 6 ms 33116 KB Output is correct
64 Correct 6 ms 33232 KB Output is correct
65 Correct 533 ms 35704 KB Output is correct
66 Correct 566 ms 35900 KB Output is correct
67 Correct 527 ms 35908 KB Output is correct
68 Correct 526 ms 35900 KB Output is correct
69 Correct 537 ms 35908 KB Output is correct
70 Correct 534 ms 35904 KB Output is correct
71 Correct 549 ms 35900 KB Output is correct
72 Correct 529 ms 35904 KB Output is correct
73 Correct 553 ms 35920 KB Output is correct
74 Correct 534 ms 35904 KB Output is correct
75 Correct 531 ms 35672 KB Output is correct
76 Correct 546 ms 35900 KB Output is correct
77 Correct 528 ms 35908 KB Output is correct
78 Correct 525 ms 35904 KB Output is correct
79 Correct 533 ms 35920 KB Output is correct
80 Correct 534 ms 35904 KB Output is correct
81 Correct 526 ms 35664 KB Output is correct
82 Correct 557 ms 35908 KB Output is correct
83 Correct 576 ms 35900 KB Output is correct
84 Correct 534 ms 36140 KB Output is correct
85 Correct 528 ms 35904 KB Output is correct
86 Correct 553 ms 35904 KB Output is correct
87 Correct 533 ms 35664 KB Output is correct
88 Correct 535 ms 35664 KB Output is correct
89 Correct 534 ms 35900 KB Output is correct
90 Correct 541 ms 35924 KB Output is correct
91 Correct 564 ms 35668 KB Output is correct
92 Correct 542 ms 35904 KB Output is correct
93 Correct 544 ms 35904 KB Output is correct
94 Correct 535 ms 35664 KB Output is correct
95 Correct 547 ms 35904 KB Output is correct
96 Correct 546 ms 35904 KB Output is correct
97 Correct 596 ms 35664 KB Output is correct
98 Correct 542 ms 35904 KB Output is correct
99 Correct 540 ms 35908 KB Output is correct
100 Correct 543 ms 35668 KB Output is correct
101 Correct 539 ms 35664 KB Output is correct
102 Correct 563 ms 36108 KB Output is correct