# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
127194 |
2019-07-09T06:03:30 Z |
dndhk |
Lamps (JOI19_lamps) |
C++14 |
|
230 ms |
35928 KB |
#include <bits/stdc++.h>
#define pb push_back
#define all(v) ((v).begin(), (v).end())
#define sortv(v) sort(all(v))
#define sz(v) ((int)(v).size())
#define uniqv(v) (v).erase(unique(all(v)), (v).end())
#define umax(a, b) (a)=max((a), (b))
#define umin(a, b) (a)=min((a), (b))
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define rep(i,n) FOR(i,1,n)
#define rep0(i,n) FOR(i,0,(int)(n)-1)
#define FI first
#define SE second
#define INF 1000000000
#define INFLL 1000000000000000000LL
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAX_N = 1000000;
int N;
string A, B;
pii type[MAX_N+1];
int dp[MAX_N+10][2][3];
int main(){
scanf("%d", &N);
cin>>A;
cin>>B;
for(int i=0; i<N; i++){
type[i+1] = {(A[i] - '0'), (B[i] - '0')};
}
for(int i=0; i<2; i++){
for(int j=0; j<3; j++){
dp[0][i][j] = INF;
}
}
dp[0][0][0] = 0;
for(int n=1; n<=N; n++){
for(int i=0; i<2; i++){
for(int j=0; j<3; j++){
dp[n][i][j] = INF;
for(int i2=0; i2<2; i2++){
for(int j2=0; j2<3; j2++){
int pl = 0;
if(i==1 && i2==0) pl++;
if(j!=j2 && j!=0) pl++;
dp[n][i][j] = min(dp[n][i][j], dp[n-1][i2][j2] + pl);
}
}
if(type[n].first==0){
if(type[n].second==0){
dp[n][0][2] = dp[n][1][0] = dp[n][1][1] = INF;
}else{
dp[n][0][0] = dp[n][0][1] = dp[n][1][2] = INF;
}
}else{
if(type[n].second==0){
dp[n][0][0] = dp[n][0][2] = dp[n][1][1] = INF;
}else{
dp[n][0][1] = dp[n][1][0] = dp[n][1][2] = INF;
}
}
}
}
}
int ans = INF;
for(int i=0; i<2; i++){
for(int j=0; j<3; j++){
ans = min(ans, dp[N][i][j]);
}
}
cout<<ans;
return 0;
}
Compilation message
lamp.cpp: In function 'int main()':
lamp.cpp:32:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &N);
~~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
380 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
504 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
2 ms |
376 KB |
Output is correct |
28 |
Correct |
2 ms |
376 KB |
Output is correct |
29 |
Correct |
2 ms |
376 KB |
Output is correct |
30 |
Correct |
2 ms |
376 KB |
Output is correct |
31 |
Correct |
2 ms |
256 KB |
Output is correct |
32 |
Correct |
2 ms |
380 KB |
Output is correct |
33 |
Correct |
2 ms |
376 KB |
Output is correct |
34 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
380 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
504 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
2 ms |
376 KB |
Output is correct |
28 |
Correct |
2 ms |
376 KB |
Output is correct |
29 |
Correct |
2 ms |
376 KB |
Output is correct |
30 |
Correct |
2 ms |
376 KB |
Output is correct |
31 |
Correct |
2 ms |
256 KB |
Output is correct |
32 |
Correct |
2 ms |
380 KB |
Output is correct |
33 |
Correct |
2 ms |
376 KB |
Output is correct |
34 |
Correct |
2 ms |
376 KB |
Output is correct |
35 |
Correct |
3 ms |
376 KB |
Output is correct |
36 |
Correct |
3 ms |
504 KB |
Output is correct |
37 |
Correct |
2 ms |
376 KB |
Output is correct |
38 |
Correct |
2 ms |
376 KB |
Output is correct |
39 |
Correct |
3 ms |
380 KB |
Output is correct |
40 |
Correct |
2 ms |
376 KB |
Output is correct |
41 |
Correct |
3 ms |
376 KB |
Output is correct |
42 |
Correct |
2 ms |
376 KB |
Output is correct |
43 |
Correct |
3 ms |
376 KB |
Output is correct |
44 |
Correct |
2 ms |
376 KB |
Output is correct |
45 |
Correct |
3 ms |
376 KB |
Output is correct |
46 |
Correct |
2 ms |
376 KB |
Output is correct |
47 |
Correct |
2 ms |
376 KB |
Output is correct |
48 |
Correct |
2 ms |
376 KB |
Output is correct |
49 |
Correct |
3 ms |
376 KB |
Output is correct |
50 |
Correct |
2 ms |
376 KB |
Output is correct |
51 |
Correct |
2 ms |
376 KB |
Output is correct |
52 |
Correct |
2 ms |
504 KB |
Output is correct |
53 |
Correct |
2 ms |
376 KB |
Output is correct |
54 |
Correct |
3 ms |
376 KB |
Output is correct |
55 |
Correct |
3 ms |
376 KB |
Output is correct |
56 |
Correct |
2 ms |
376 KB |
Output is correct |
57 |
Correct |
2 ms |
376 KB |
Output is correct |
58 |
Correct |
3 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
213 ms |
33736 KB |
Output is correct |
8 |
Correct |
219 ms |
33740 KB |
Output is correct |
9 |
Correct |
216 ms |
33864 KB |
Output is correct |
10 |
Correct |
217 ms |
33740 KB |
Output is correct |
11 |
Correct |
217 ms |
33908 KB |
Output is correct |
12 |
Correct |
219 ms |
33804 KB |
Output is correct |
13 |
Correct |
216 ms |
33772 KB |
Output is correct |
14 |
Correct |
217 ms |
33808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
380 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
504 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
2 ms |
376 KB |
Output is correct |
28 |
Correct |
2 ms |
376 KB |
Output is correct |
29 |
Correct |
2 ms |
376 KB |
Output is correct |
30 |
Correct |
2 ms |
376 KB |
Output is correct |
31 |
Correct |
2 ms |
256 KB |
Output is correct |
32 |
Correct |
2 ms |
380 KB |
Output is correct |
33 |
Correct |
2 ms |
376 KB |
Output is correct |
34 |
Correct |
2 ms |
376 KB |
Output is correct |
35 |
Correct |
3 ms |
376 KB |
Output is correct |
36 |
Correct |
3 ms |
504 KB |
Output is correct |
37 |
Correct |
2 ms |
376 KB |
Output is correct |
38 |
Correct |
2 ms |
376 KB |
Output is correct |
39 |
Correct |
3 ms |
380 KB |
Output is correct |
40 |
Correct |
2 ms |
376 KB |
Output is correct |
41 |
Correct |
3 ms |
376 KB |
Output is correct |
42 |
Correct |
2 ms |
376 KB |
Output is correct |
43 |
Correct |
3 ms |
376 KB |
Output is correct |
44 |
Correct |
2 ms |
376 KB |
Output is correct |
45 |
Correct |
3 ms |
376 KB |
Output is correct |
46 |
Correct |
2 ms |
376 KB |
Output is correct |
47 |
Correct |
2 ms |
376 KB |
Output is correct |
48 |
Correct |
2 ms |
376 KB |
Output is correct |
49 |
Correct |
3 ms |
376 KB |
Output is correct |
50 |
Correct |
2 ms |
376 KB |
Output is correct |
51 |
Correct |
2 ms |
376 KB |
Output is correct |
52 |
Correct |
2 ms |
504 KB |
Output is correct |
53 |
Correct |
2 ms |
376 KB |
Output is correct |
54 |
Correct |
3 ms |
376 KB |
Output is correct |
55 |
Correct |
3 ms |
376 KB |
Output is correct |
56 |
Correct |
2 ms |
376 KB |
Output is correct |
57 |
Correct |
2 ms |
376 KB |
Output is correct |
58 |
Correct |
3 ms |
376 KB |
Output is correct |
59 |
Correct |
2 ms |
376 KB |
Output is correct |
60 |
Correct |
2 ms |
376 KB |
Output is correct |
61 |
Correct |
2 ms |
376 KB |
Output is correct |
62 |
Correct |
2 ms |
376 KB |
Output is correct |
63 |
Correct |
2 ms |
376 KB |
Output is correct |
64 |
Correct |
2 ms |
256 KB |
Output is correct |
65 |
Correct |
213 ms |
33736 KB |
Output is correct |
66 |
Correct |
219 ms |
33740 KB |
Output is correct |
67 |
Correct |
216 ms |
33864 KB |
Output is correct |
68 |
Correct |
217 ms |
33740 KB |
Output is correct |
69 |
Correct |
217 ms |
33908 KB |
Output is correct |
70 |
Correct |
219 ms |
33804 KB |
Output is correct |
71 |
Correct |
216 ms |
33772 KB |
Output is correct |
72 |
Correct |
217 ms |
33808 KB |
Output is correct |
73 |
Correct |
217 ms |
35748 KB |
Output is correct |
74 |
Correct |
217 ms |
35700 KB |
Output is correct |
75 |
Correct |
219 ms |
35760 KB |
Output is correct |
76 |
Correct |
219 ms |
35684 KB |
Output is correct |
77 |
Correct |
220 ms |
35728 KB |
Output is correct |
78 |
Correct |
226 ms |
35628 KB |
Output is correct |
79 |
Correct |
216 ms |
35852 KB |
Output is correct |
80 |
Correct |
224 ms |
35656 KB |
Output is correct |
81 |
Correct |
219 ms |
35716 KB |
Output is correct |
82 |
Correct |
220 ms |
35900 KB |
Output is correct |
83 |
Correct |
222 ms |
35692 KB |
Output is correct |
84 |
Correct |
224 ms |
35688 KB |
Output is correct |
85 |
Correct |
224 ms |
35784 KB |
Output is correct |
86 |
Correct |
222 ms |
35688 KB |
Output is correct |
87 |
Correct |
223 ms |
35636 KB |
Output is correct |
88 |
Correct |
223 ms |
35700 KB |
Output is correct |
89 |
Correct |
223 ms |
35928 KB |
Output is correct |
90 |
Correct |
224 ms |
35736 KB |
Output is correct |
91 |
Correct |
225 ms |
35668 KB |
Output is correct |
92 |
Correct |
225 ms |
35616 KB |
Output is correct |
93 |
Correct |
226 ms |
35704 KB |
Output is correct |
94 |
Correct |
227 ms |
35712 KB |
Output is correct |
95 |
Correct |
227 ms |
35844 KB |
Output is correct |
96 |
Correct |
230 ms |
35684 KB |
Output is correct |
97 |
Correct |
229 ms |
35812 KB |
Output is correct |
98 |
Correct |
226 ms |
35684 KB |
Output is correct |
99 |
Correct |
227 ms |
35680 KB |
Output is correct |
100 |
Correct |
227 ms |
35720 KB |
Output is correct |
101 |
Correct |
228 ms |
35696 KB |
Output is correct |
102 |
Correct |
226 ms |
35920 KB |
Output is correct |