# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
972076 |
2024-04-30T03:46:05 Z |
vjudge1 |
Lamps (JOI19_lamps) |
C++17 |
|
111 ms |
66700 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define FORD(i, a, b) for (int i = b; i >= a; i --)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPD(i, n) for (int i = n - 1; i >= 0; --i)
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
constexpr ll LINF = (1ll << 60);
constexpr int INF = (1ll << 30);
constexpr int Mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void setupIO(){
#define name "Whisper"
//Phu Trong from Nguyen Tat Thanh High School for gifted student
srand(time(NULL));
cin.tie(nullptr)->sync_with_stdio(false); cout.tie(nullptr);
//freopen(name".inp", "r", stdin);
//freopen(name".out", "w", stdout);
cout << fixed << setprecision(10);
}
template <class X, class Y>
bool minimize(X &x, const Y &y){
X eps = 1e-9;
if (x > y + eps) {x = y; return 1;}
return 0;
}
template <class X, class Y>
bool maximize(X &x, const Y &y){
X eps = 1e-9;
if (x + eps < y) {x = y; return 1;}
return 0;
}
int nArr;
string s, t;
const int MAX = 1e6 + 5;
int dp[MAX][2][3];
#define NOT 0
#define OFF 1
#define ON 2
int A[MAX], B[MAX];
void Whisper(){
cin >> nArr >> s >> t;
FOR(i, 1, nArr) A[i] = (s[i - 1] - '0');
FOR(i, 1, nArr) B[i] = (t[i - 1] - '0');
memset(dp, 0x3f, sizeof dp);
dp[0][0][0] = 0;
REP(i, nArr) REP(state, 2) REP(k, 3) REP(nxt_state, 2) REP(v, 3){
int bit;
if (v == NOT) bit = A[i + 1];
else bit = v - 1;
if(nxt_state) bit ^= 1;
if(bit == B[i + 1])
minimize(dp[i + 1][nxt_state][v], dp[i][state][k] + (k != v && v > 0) + (state < nxt_state));
}
int ans = INF;
REP(state, 2) REP(k, 3) minimize(ans, dp[nArr][state][k]);
cout << ans;
}
signed main(){
setupIO();
int Test = 1;
// cin >> Test;
for ( int i = 1 ; i <= Test ; i++ ){
Whisper();
if (i < Test) cout << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
50520 KB |
Output is correct |
2 |
Correct |
13 ms |
50776 KB |
Output is correct |
3 |
Correct |
11 ms |
50424 KB |
Output is correct |
4 |
Correct |
12 ms |
50524 KB |
Output is correct |
5 |
Correct |
13 ms |
50528 KB |
Output is correct |
6 |
Correct |
12 ms |
50424 KB |
Output is correct |
7 |
Correct |
12 ms |
50528 KB |
Output is correct |
8 |
Correct |
12 ms |
50524 KB |
Output is correct |
9 |
Correct |
12 ms |
50408 KB |
Output is correct |
10 |
Correct |
12 ms |
50524 KB |
Output is correct |
11 |
Correct |
12 ms |
50524 KB |
Output is correct |
12 |
Correct |
12 ms |
50380 KB |
Output is correct |
13 |
Correct |
11 ms |
50524 KB |
Output is correct |
14 |
Correct |
12 ms |
50524 KB |
Output is correct |
15 |
Correct |
12 ms |
50524 KB |
Output is correct |
16 |
Correct |
12 ms |
50484 KB |
Output is correct |
17 |
Correct |
12 ms |
50520 KB |
Output is correct |
18 |
Correct |
12 ms |
50444 KB |
Output is correct |
19 |
Correct |
12 ms |
50412 KB |
Output is correct |
20 |
Correct |
11 ms |
50524 KB |
Output is correct |
21 |
Correct |
12 ms |
50524 KB |
Output is correct |
22 |
Correct |
12 ms |
50524 KB |
Output is correct |
23 |
Correct |
12 ms |
50524 KB |
Output is correct |
24 |
Correct |
12 ms |
50524 KB |
Output is correct |
25 |
Correct |
12 ms |
50524 KB |
Output is correct |
26 |
Correct |
12 ms |
50524 KB |
Output is correct |
27 |
Correct |
12 ms |
50524 KB |
Output is correct |
28 |
Correct |
12 ms |
50780 KB |
Output is correct |
29 |
Correct |
12 ms |
50520 KB |
Output is correct |
30 |
Correct |
11 ms |
50520 KB |
Output is correct |
31 |
Correct |
12 ms |
50536 KB |
Output is correct |
32 |
Correct |
12 ms |
50724 KB |
Output is correct |
33 |
Correct |
11 ms |
50524 KB |
Output is correct |
34 |
Correct |
11 ms |
50524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
50520 KB |
Output is correct |
2 |
Correct |
13 ms |
50776 KB |
Output is correct |
3 |
Correct |
11 ms |
50424 KB |
Output is correct |
4 |
Correct |
12 ms |
50524 KB |
Output is correct |
5 |
Correct |
13 ms |
50528 KB |
Output is correct |
6 |
Correct |
12 ms |
50424 KB |
Output is correct |
7 |
Correct |
12 ms |
50528 KB |
Output is correct |
8 |
Correct |
12 ms |
50524 KB |
Output is correct |
9 |
Correct |
12 ms |
50408 KB |
Output is correct |
10 |
Correct |
12 ms |
50524 KB |
Output is correct |
11 |
Correct |
12 ms |
50524 KB |
Output is correct |
12 |
Correct |
12 ms |
50380 KB |
Output is correct |
13 |
Correct |
11 ms |
50524 KB |
Output is correct |
14 |
Correct |
12 ms |
50524 KB |
Output is correct |
15 |
Correct |
12 ms |
50524 KB |
Output is correct |
16 |
Correct |
12 ms |
50484 KB |
Output is correct |
17 |
Correct |
12 ms |
50520 KB |
Output is correct |
18 |
Correct |
12 ms |
50444 KB |
Output is correct |
19 |
Correct |
12 ms |
50412 KB |
Output is correct |
20 |
Correct |
11 ms |
50524 KB |
Output is correct |
21 |
Correct |
12 ms |
50524 KB |
Output is correct |
22 |
Correct |
12 ms |
50524 KB |
Output is correct |
23 |
Correct |
12 ms |
50524 KB |
Output is correct |
24 |
Correct |
12 ms |
50524 KB |
Output is correct |
25 |
Correct |
12 ms |
50524 KB |
Output is correct |
26 |
Correct |
12 ms |
50524 KB |
Output is correct |
27 |
Correct |
12 ms |
50524 KB |
Output is correct |
28 |
Correct |
12 ms |
50780 KB |
Output is correct |
29 |
Correct |
12 ms |
50520 KB |
Output is correct |
30 |
Correct |
11 ms |
50520 KB |
Output is correct |
31 |
Correct |
12 ms |
50536 KB |
Output is correct |
32 |
Correct |
12 ms |
50724 KB |
Output is correct |
33 |
Correct |
11 ms |
50524 KB |
Output is correct |
34 |
Correct |
11 ms |
50524 KB |
Output is correct |
35 |
Correct |
11 ms |
50524 KB |
Output is correct |
36 |
Correct |
11 ms |
50608 KB |
Output is correct |
37 |
Correct |
13 ms |
50520 KB |
Output is correct |
38 |
Correct |
12 ms |
50524 KB |
Output is correct |
39 |
Correct |
12 ms |
50524 KB |
Output is correct |
40 |
Correct |
12 ms |
50524 KB |
Output is correct |
41 |
Correct |
11 ms |
50388 KB |
Output is correct |
42 |
Correct |
11 ms |
50524 KB |
Output is correct |
43 |
Correct |
11 ms |
50472 KB |
Output is correct |
44 |
Correct |
12 ms |
50524 KB |
Output is correct |
45 |
Correct |
12 ms |
50524 KB |
Output is correct |
46 |
Correct |
11 ms |
50520 KB |
Output is correct |
47 |
Correct |
12 ms |
50524 KB |
Output is correct |
48 |
Correct |
15 ms |
50524 KB |
Output is correct |
49 |
Correct |
12 ms |
50524 KB |
Output is correct |
50 |
Correct |
12 ms |
50464 KB |
Output is correct |
51 |
Correct |
12 ms |
50524 KB |
Output is correct |
52 |
Correct |
12 ms |
50524 KB |
Output is correct |
53 |
Correct |
12 ms |
50524 KB |
Output is correct |
54 |
Correct |
12 ms |
50524 KB |
Output is correct |
55 |
Correct |
13 ms |
50524 KB |
Output is correct |
56 |
Correct |
14 ms |
50524 KB |
Output is correct |
57 |
Correct |
13 ms |
50576 KB |
Output is correct |
58 |
Correct |
13 ms |
50524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
50524 KB |
Output is correct |
2 |
Correct |
12 ms |
50524 KB |
Output is correct |
3 |
Correct |
12 ms |
50524 KB |
Output is correct |
4 |
Correct |
13 ms |
50524 KB |
Output is correct |
5 |
Correct |
12 ms |
50508 KB |
Output is correct |
6 |
Correct |
12 ms |
50524 KB |
Output is correct |
7 |
Correct |
81 ms |
66216 KB |
Output is correct |
8 |
Correct |
94 ms |
66476 KB |
Output is correct |
9 |
Correct |
97 ms |
66700 KB |
Output is correct |
10 |
Correct |
103 ms |
66208 KB |
Output is correct |
11 |
Correct |
101 ms |
66452 KB |
Output is correct |
12 |
Correct |
84 ms |
66504 KB |
Output is correct |
13 |
Correct |
96 ms |
66468 KB |
Output is correct |
14 |
Correct |
87 ms |
66312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
50520 KB |
Output is correct |
2 |
Correct |
13 ms |
50776 KB |
Output is correct |
3 |
Correct |
11 ms |
50424 KB |
Output is correct |
4 |
Correct |
12 ms |
50524 KB |
Output is correct |
5 |
Correct |
13 ms |
50528 KB |
Output is correct |
6 |
Correct |
12 ms |
50424 KB |
Output is correct |
7 |
Correct |
12 ms |
50528 KB |
Output is correct |
8 |
Correct |
12 ms |
50524 KB |
Output is correct |
9 |
Correct |
12 ms |
50408 KB |
Output is correct |
10 |
Correct |
12 ms |
50524 KB |
Output is correct |
11 |
Correct |
12 ms |
50524 KB |
Output is correct |
12 |
Correct |
12 ms |
50380 KB |
Output is correct |
13 |
Correct |
11 ms |
50524 KB |
Output is correct |
14 |
Correct |
12 ms |
50524 KB |
Output is correct |
15 |
Correct |
12 ms |
50524 KB |
Output is correct |
16 |
Correct |
12 ms |
50484 KB |
Output is correct |
17 |
Correct |
12 ms |
50520 KB |
Output is correct |
18 |
Correct |
12 ms |
50444 KB |
Output is correct |
19 |
Correct |
12 ms |
50412 KB |
Output is correct |
20 |
Correct |
11 ms |
50524 KB |
Output is correct |
21 |
Correct |
12 ms |
50524 KB |
Output is correct |
22 |
Correct |
12 ms |
50524 KB |
Output is correct |
23 |
Correct |
12 ms |
50524 KB |
Output is correct |
24 |
Correct |
12 ms |
50524 KB |
Output is correct |
25 |
Correct |
12 ms |
50524 KB |
Output is correct |
26 |
Correct |
12 ms |
50524 KB |
Output is correct |
27 |
Correct |
12 ms |
50524 KB |
Output is correct |
28 |
Correct |
12 ms |
50780 KB |
Output is correct |
29 |
Correct |
12 ms |
50520 KB |
Output is correct |
30 |
Correct |
11 ms |
50520 KB |
Output is correct |
31 |
Correct |
12 ms |
50536 KB |
Output is correct |
32 |
Correct |
12 ms |
50724 KB |
Output is correct |
33 |
Correct |
11 ms |
50524 KB |
Output is correct |
34 |
Correct |
11 ms |
50524 KB |
Output is correct |
35 |
Correct |
11 ms |
50524 KB |
Output is correct |
36 |
Correct |
11 ms |
50608 KB |
Output is correct |
37 |
Correct |
13 ms |
50520 KB |
Output is correct |
38 |
Correct |
12 ms |
50524 KB |
Output is correct |
39 |
Correct |
12 ms |
50524 KB |
Output is correct |
40 |
Correct |
12 ms |
50524 KB |
Output is correct |
41 |
Correct |
11 ms |
50388 KB |
Output is correct |
42 |
Correct |
11 ms |
50524 KB |
Output is correct |
43 |
Correct |
11 ms |
50472 KB |
Output is correct |
44 |
Correct |
12 ms |
50524 KB |
Output is correct |
45 |
Correct |
12 ms |
50524 KB |
Output is correct |
46 |
Correct |
11 ms |
50520 KB |
Output is correct |
47 |
Correct |
12 ms |
50524 KB |
Output is correct |
48 |
Correct |
15 ms |
50524 KB |
Output is correct |
49 |
Correct |
12 ms |
50524 KB |
Output is correct |
50 |
Correct |
12 ms |
50464 KB |
Output is correct |
51 |
Correct |
12 ms |
50524 KB |
Output is correct |
52 |
Correct |
12 ms |
50524 KB |
Output is correct |
53 |
Correct |
12 ms |
50524 KB |
Output is correct |
54 |
Correct |
12 ms |
50524 KB |
Output is correct |
55 |
Correct |
13 ms |
50524 KB |
Output is correct |
56 |
Correct |
14 ms |
50524 KB |
Output is correct |
57 |
Correct |
13 ms |
50576 KB |
Output is correct |
58 |
Correct |
13 ms |
50524 KB |
Output is correct |
59 |
Correct |
13 ms |
50524 KB |
Output is correct |
60 |
Correct |
12 ms |
50524 KB |
Output is correct |
61 |
Correct |
12 ms |
50524 KB |
Output is correct |
62 |
Correct |
13 ms |
50524 KB |
Output is correct |
63 |
Correct |
12 ms |
50508 KB |
Output is correct |
64 |
Correct |
12 ms |
50524 KB |
Output is correct |
65 |
Correct |
81 ms |
66216 KB |
Output is correct |
66 |
Correct |
94 ms |
66476 KB |
Output is correct |
67 |
Correct |
97 ms |
66700 KB |
Output is correct |
68 |
Correct |
103 ms |
66208 KB |
Output is correct |
69 |
Correct |
101 ms |
66452 KB |
Output is correct |
70 |
Correct |
84 ms |
66504 KB |
Output is correct |
71 |
Correct |
96 ms |
66468 KB |
Output is correct |
72 |
Correct |
87 ms |
66312 KB |
Output is correct |
73 |
Correct |
94 ms |
66208 KB |
Output is correct |
74 |
Correct |
93 ms |
66440 KB |
Output is correct |
75 |
Correct |
93 ms |
66208 KB |
Output is correct |
76 |
Correct |
87 ms |
66208 KB |
Output is correct |
77 |
Correct |
89 ms |
66212 KB |
Output is correct |
78 |
Correct |
90 ms |
66216 KB |
Output is correct |
79 |
Correct |
86 ms |
66216 KB |
Output is correct |
80 |
Correct |
89 ms |
66216 KB |
Output is correct |
81 |
Correct |
88 ms |
66208 KB |
Output is correct |
82 |
Correct |
89 ms |
66212 KB |
Output is correct |
83 |
Correct |
99 ms |
66476 KB |
Output is correct |
84 |
Correct |
98 ms |
66468 KB |
Output is correct |
85 |
Correct |
102 ms |
66220 KB |
Output is correct |
86 |
Correct |
97 ms |
66208 KB |
Output is correct |
87 |
Correct |
101 ms |
66444 KB |
Output is correct |
88 |
Correct |
103 ms |
66212 KB |
Output is correct |
89 |
Correct |
100 ms |
66448 KB |
Output is correct |
90 |
Correct |
99 ms |
66292 KB |
Output is correct |
91 |
Correct |
105 ms |
66448 KB |
Output is correct |
92 |
Correct |
111 ms |
66472 KB |
Output is correct |
93 |
Correct |
110 ms |
66444 KB |
Output is correct |
94 |
Correct |
110 ms |
66452 KB |
Output is correct |
95 |
Correct |
109 ms |
66208 KB |
Output is correct |
96 |
Correct |
110 ms |
66212 KB |
Output is correct |
97 |
Correct |
109 ms |
66448 KB |
Output is correct |
98 |
Correct |
108 ms |
66212 KB |
Output is correct |
99 |
Correct |
109 ms |
66448 KB |
Output is correct |
100 |
Correct |
108 ms |
66216 KB |
Output is correct |
101 |
Correct |
108 ms |
66212 KB |
Output is correct |
102 |
Correct |
109 ms |
66388 KB |
Output is correct |