Submission #1023339

# Submission time Handle Problem Language Result Execution time Memory
1023339 2024-07-14T16:27:53 Z NintsiChkhaidze Lamps (JOI19_lamps) C++17
100 / 100
358 ms 200180 KB
#include <bits/stdc++.h>
#include <ostream>
#define pb push_back
#define s second
#define f first
#define pb push_back
#define pii pair <int,int>
#define ll long long
#define left h*2,l,(l + r)/2
#define right h*2+1,(l + r)/2 + 1,r
#define int ll
using namespace std;
 
const int N = 1e6 + 5,inf = 1e9;
int dp[N][5][5];

signed main() {
  ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
  
  int n;
  cin>>n;

  string A;
  cin>>A;

  string B;
  cin>>B;

  A = '$' + A;
  B = '%' + B;

  for (int i = 0; i <= n; i++)
    for (int j = 0; j < 4; j++)
      for (int k = 0; k < 4; k++)
        dp[i][j][k] = inf;

  dp[0][0][0] = 0;
  for (int i = 1; i <= n; i++){
    
    for (int j = 0; j < 4; j++){
      for (int k = 0; k < 4; k++){
        if (dp[i - 1][j][k] == inf) continue;

        for (int j1 = 0; j1 < 4; j1++){
          for (int k1 = 0; k1 < 4; k1++){
            if (!j1 && k1) continue;
            if (j1 == k1 && j1) continue;

            int val = (A[i] - '0');
            if (j1 == 1) val = 1;
            if (j1 == 2) val = 0;
            if (j1 == 3) val ^= 1;

            if (k1 == 1) val = 1;
            if (k1 == 2) val = 0;
            if (k1 == 3) val ^= 1;

            int f = (B[i] - '0');
            if (val != f) continue;

            int c = 0;
            if (j1 && k1){
              if (j1 == j && k1 == k) c = 0;
              else if (j1 == k && k1 == j) c = 1;
              else {
                if (j1 != j && j1 != k) c++;
                if (k1 != j && k1 != k) c++;
              }
            }else {
              if (j1 && j1 != k && j1 != j) ++c;
            }

            dp[i][j1][k1] = min(dp[i][j1][k1],c + dp[i - 1][j][k]);
          }
        }
      }
    }
  }

  int ans = inf;
  for (int j = 0; j < 4; j++)
    for (int k = 0; k < 4; k++)
      ans=min(ans,dp[n][j][k]);

  cout<<ans<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 472 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 468 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 472 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 468 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 856 KB Output is correct
36 Correct 1 ms 860 KB Output is correct
37 Correct 1 ms 860 KB Output is correct
38 Correct 1 ms 860 KB Output is correct
39 Correct 1 ms 860 KB Output is correct
40 Correct 1 ms 860 KB Output is correct
41 Correct 1 ms 860 KB Output is correct
42 Correct 1 ms 860 KB Output is correct
43 Correct 1 ms 860 KB Output is correct
44 Correct 1 ms 860 KB Output is correct
45 Correct 1 ms 860 KB Output is correct
46 Correct 1 ms 860 KB Output is correct
47 Correct 1 ms 860 KB Output is correct
48 Correct 1 ms 860 KB Output is correct
49 Correct 1 ms 860 KB Output is correct
50 Correct 1 ms 860 KB Output is correct
51 Correct 1 ms 860 KB Output is correct
52 Correct 1 ms 856 KB Output is correct
53 Correct 1 ms 860 KB Output is correct
54 Correct 1 ms 856 KB Output is correct
55 Correct 1 ms 860 KB Output is correct
56 Correct 1 ms 860 KB Output is correct
57 Correct 1 ms 860 KB Output is correct
58 Correct 1 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 464 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 307 ms 199912 KB Output is correct
8 Correct 303 ms 199924 KB Output is correct
9 Correct 308 ms 199932 KB Output is correct
10 Correct 303 ms 199916 KB Output is correct
11 Correct 308 ms 199924 KB Output is correct
12 Correct 300 ms 199924 KB Output is correct
13 Correct 308 ms 199924 KB Output is correct
14 Correct 303 ms 199940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 472 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 468 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 856 KB Output is correct
36 Correct 1 ms 860 KB Output is correct
37 Correct 1 ms 860 KB Output is correct
38 Correct 1 ms 860 KB Output is correct
39 Correct 1 ms 860 KB Output is correct
40 Correct 1 ms 860 KB Output is correct
41 Correct 1 ms 860 KB Output is correct
42 Correct 1 ms 860 KB Output is correct
43 Correct 1 ms 860 KB Output is correct
44 Correct 1 ms 860 KB Output is correct
45 Correct 1 ms 860 KB Output is correct
46 Correct 1 ms 860 KB Output is correct
47 Correct 1 ms 860 KB Output is correct
48 Correct 1 ms 860 KB Output is correct
49 Correct 1 ms 860 KB Output is correct
50 Correct 1 ms 860 KB Output is correct
51 Correct 1 ms 860 KB Output is correct
52 Correct 1 ms 856 KB Output is correct
53 Correct 1 ms 860 KB Output is correct
54 Correct 1 ms 856 KB Output is correct
55 Correct 1 ms 860 KB Output is correct
56 Correct 1 ms 860 KB Output is correct
57 Correct 1 ms 860 KB Output is correct
58 Correct 1 ms 860 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 0 ms 464 KB Output is correct
61 Correct 0 ms 348 KB Output is correct
62 Correct 0 ms 348 KB Output is correct
63 Correct 0 ms 348 KB Output is correct
64 Correct 0 ms 348 KB Output is correct
65 Correct 307 ms 199912 KB Output is correct
66 Correct 303 ms 199924 KB Output is correct
67 Correct 308 ms 199932 KB Output is correct
68 Correct 303 ms 199916 KB Output is correct
69 Correct 308 ms 199924 KB Output is correct
70 Correct 300 ms 199924 KB Output is correct
71 Correct 308 ms 199924 KB Output is correct
72 Correct 303 ms 199940 KB Output is correct
73 Correct 318 ms 199920 KB Output is correct
74 Correct 295 ms 200000 KB Output is correct
75 Correct 305 ms 199924 KB Output is correct
76 Correct 303 ms 199820 KB Output is correct
77 Correct 309 ms 199996 KB Output is correct
78 Correct 302 ms 199928 KB Output is correct
79 Correct 350 ms 199924 KB Output is correct
80 Correct 318 ms 199984 KB Output is correct
81 Correct 310 ms 199924 KB Output is correct
82 Correct 310 ms 200060 KB Output is correct
83 Correct 305 ms 199924 KB Output is correct
84 Correct 322 ms 199924 KB Output is correct
85 Correct 302 ms 199988 KB Output is correct
86 Correct 311 ms 200180 KB Output is correct
87 Correct 306 ms 200040 KB Output is correct
88 Correct 313 ms 199988 KB Output is correct
89 Correct 321 ms 199924 KB Output is correct
90 Correct 344 ms 199868 KB Output is correct
91 Correct 316 ms 200068 KB Output is correct
92 Correct 319 ms 199880 KB Output is correct
93 Correct 323 ms 200048 KB Output is correct
94 Correct 358 ms 200060 KB Output is correct
95 Correct 329 ms 199864 KB Output is correct
96 Correct 317 ms 199828 KB Output is correct
97 Correct 343 ms 199936 KB Output is correct
98 Correct 329 ms 199936 KB Output is correct
99 Correct 326 ms 199920 KB Output is correct
100 Correct 318 ms 199924 KB Output is correct
101 Correct 343 ms 200128 KB Output is correct
102 Correct 320 ms 199924 KB Output is correct