답안 #211160

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
211160 2020-03-19T10:41:08 Z amiratou Lamps (JOI19_lamps) C++14
100 / 100
131 ms 106316 KB
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define rando mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define fi first
#define se second
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define debugii(x) cerr << " - " << #x << ": " << x.fi<<","<<x.se << endl;
#define sep() cerr << "--------------------" << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ld long double
#define ll long long
//#define int ll
#define ii pair<int,int>
#define v vector<int>
#define vii vector<ii>
#define vv vector<vector<int> >
#define mp make_pair
#define INF 1000000000
#define pb push_back
#define EPS 1e-9
const int MOD = 1000000007; // 998244353
int dp[1000006][2][3],n;
string A,B;
char conv(char a,int t,int s){
	if(!s)a='0';
	if(s==1)a='1';
	if(t)a=(char)(1-(int)(a-'0')+'0');
	return a;
}
int solve(int idx,int t,int s){
	if(idx==n)
		return 0;
	if(dp[idx][t][s]!=-1)
		return dp[idx][t][s];
	int ans=INF;
	for (int i = 0; i < 2; ++i)
		for (int j = 0; j < 3; ++j)
		{
			int cost=0;
			cost+=(i?(i!=t):0)+((j!=2)?(j!=s):0);
			if(conv(A[idx],i,j)!=B[idx])continue;
			ans=min(ans,solve(idx+1,i,j)+cost);
		}
	return dp[idx][t][s]=ans;
}
int32_t main(){
	boost;
	//freopen(".in","r",stdin);
	memset(dp,-1,sizeof dp);
	cin>>n>>A>>B;
	cout<<solve(0,0,2);
	return 0;
}
//long long
//array bounds
//special cases
//binary search
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23808 KB Output is correct
2 Correct 16 ms 23808 KB Output is correct
3 Correct 17 ms 23808 KB Output is correct
4 Correct 16 ms 23808 KB Output is correct
5 Correct 17 ms 23808 KB Output is correct
6 Correct 18 ms 23808 KB Output is correct
7 Correct 16 ms 23808 KB Output is correct
8 Correct 17 ms 23936 KB Output is correct
9 Correct 18 ms 23808 KB Output is correct
10 Correct 18 ms 23808 KB Output is correct
11 Correct 17 ms 23808 KB Output is correct
12 Correct 18 ms 23808 KB Output is correct
13 Correct 17 ms 23808 KB Output is correct
14 Correct 17 ms 23808 KB Output is correct
15 Correct 17 ms 23808 KB Output is correct
16 Correct 17 ms 23808 KB Output is correct
17 Correct 18 ms 23808 KB Output is correct
18 Correct 16 ms 23936 KB Output is correct
19 Correct 19 ms 23808 KB Output is correct
20 Correct 17 ms 23808 KB Output is correct
21 Correct 18 ms 23808 KB Output is correct
22 Correct 16 ms 23808 KB Output is correct
23 Correct 17 ms 23808 KB Output is correct
24 Correct 17 ms 23808 KB Output is correct
25 Correct 18 ms 23808 KB Output is correct
26 Correct 17 ms 23808 KB Output is correct
27 Correct 17 ms 23808 KB Output is correct
28 Correct 19 ms 23808 KB Output is correct
29 Correct 17 ms 23808 KB Output is correct
30 Correct 17 ms 23808 KB Output is correct
31 Correct 18 ms 23808 KB Output is correct
32 Correct 17 ms 23808 KB Output is correct
33 Correct 17 ms 23808 KB Output is correct
34 Correct 18 ms 23808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23808 KB Output is correct
2 Correct 16 ms 23808 KB Output is correct
3 Correct 17 ms 23808 KB Output is correct
4 Correct 16 ms 23808 KB Output is correct
5 Correct 17 ms 23808 KB Output is correct
6 Correct 18 ms 23808 KB Output is correct
7 Correct 16 ms 23808 KB Output is correct
8 Correct 17 ms 23936 KB Output is correct
9 Correct 18 ms 23808 KB Output is correct
10 Correct 18 ms 23808 KB Output is correct
11 Correct 17 ms 23808 KB Output is correct
12 Correct 18 ms 23808 KB Output is correct
13 Correct 17 ms 23808 KB Output is correct
14 Correct 17 ms 23808 KB Output is correct
15 Correct 17 ms 23808 KB Output is correct
16 Correct 17 ms 23808 KB Output is correct
17 Correct 18 ms 23808 KB Output is correct
18 Correct 16 ms 23936 KB Output is correct
19 Correct 19 ms 23808 KB Output is correct
20 Correct 17 ms 23808 KB Output is correct
21 Correct 18 ms 23808 KB Output is correct
22 Correct 16 ms 23808 KB Output is correct
23 Correct 17 ms 23808 KB Output is correct
24 Correct 17 ms 23808 KB Output is correct
25 Correct 18 ms 23808 KB Output is correct
26 Correct 17 ms 23808 KB Output is correct
27 Correct 17 ms 23808 KB Output is correct
28 Correct 19 ms 23808 KB Output is correct
29 Correct 17 ms 23808 KB Output is correct
30 Correct 17 ms 23808 KB Output is correct
31 Correct 18 ms 23808 KB Output is correct
32 Correct 17 ms 23808 KB Output is correct
33 Correct 17 ms 23808 KB Output is correct
34 Correct 18 ms 23808 KB Output is correct
35 Correct 18 ms 24192 KB Output is correct
36 Correct 17 ms 23936 KB Output is correct
37 Correct 16 ms 23936 KB Output is correct
38 Correct 16 ms 23936 KB Output is correct
39 Correct 18 ms 23936 KB Output is correct
40 Correct 17 ms 23936 KB Output is correct
41 Correct 17 ms 23936 KB Output is correct
42 Correct 18 ms 23936 KB Output is correct
43 Correct 17 ms 23936 KB Output is correct
44 Correct 18 ms 23936 KB Output is correct
45 Correct 18 ms 23936 KB Output is correct
46 Correct 18 ms 23936 KB Output is correct
47 Correct 19 ms 23936 KB Output is correct
48 Correct 18 ms 23936 KB Output is correct
49 Correct 16 ms 23936 KB Output is correct
50 Correct 17 ms 24064 KB Output is correct
51 Correct 16 ms 23936 KB Output is correct
52 Correct 17 ms 24064 KB Output is correct
53 Correct 17 ms 23936 KB Output is correct
54 Correct 17 ms 23928 KB Output is correct
55 Correct 17 ms 23936 KB Output is correct
56 Correct 17 ms 24064 KB Output is correct
57 Correct 17 ms 23936 KB Output is correct
58 Correct 17 ms 24064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23808 KB Output is correct
2 Correct 18 ms 23808 KB Output is correct
3 Correct 17 ms 23808 KB Output is correct
4 Correct 18 ms 23808 KB Output is correct
5 Correct 17 ms 23808 KB Output is correct
6 Correct 17 ms 23808 KB Output is correct
7 Correct 114 ms 104268 KB Output is correct
8 Correct 116 ms 104260 KB Output is correct
9 Correct 116 ms 104140 KB Output is correct
10 Correct 114 ms 104276 KB Output is correct
11 Correct 116 ms 104268 KB Output is correct
12 Correct 113 ms 104256 KB Output is correct
13 Correct 113 ms 104140 KB Output is correct
14 Correct 112 ms 104136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23808 KB Output is correct
2 Correct 16 ms 23808 KB Output is correct
3 Correct 17 ms 23808 KB Output is correct
4 Correct 16 ms 23808 KB Output is correct
5 Correct 17 ms 23808 KB Output is correct
6 Correct 18 ms 23808 KB Output is correct
7 Correct 16 ms 23808 KB Output is correct
8 Correct 17 ms 23936 KB Output is correct
9 Correct 18 ms 23808 KB Output is correct
10 Correct 18 ms 23808 KB Output is correct
11 Correct 17 ms 23808 KB Output is correct
12 Correct 18 ms 23808 KB Output is correct
13 Correct 17 ms 23808 KB Output is correct
14 Correct 17 ms 23808 KB Output is correct
15 Correct 17 ms 23808 KB Output is correct
16 Correct 17 ms 23808 KB Output is correct
17 Correct 18 ms 23808 KB Output is correct
18 Correct 16 ms 23936 KB Output is correct
19 Correct 19 ms 23808 KB Output is correct
20 Correct 17 ms 23808 KB Output is correct
21 Correct 18 ms 23808 KB Output is correct
22 Correct 16 ms 23808 KB Output is correct
23 Correct 17 ms 23808 KB Output is correct
24 Correct 17 ms 23808 KB Output is correct
25 Correct 18 ms 23808 KB Output is correct
26 Correct 17 ms 23808 KB Output is correct
27 Correct 17 ms 23808 KB Output is correct
28 Correct 19 ms 23808 KB Output is correct
29 Correct 17 ms 23808 KB Output is correct
30 Correct 17 ms 23808 KB Output is correct
31 Correct 18 ms 23808 KB Output is correct
32 Correct 17 ms 23808 KB Output is correct
33 Correct 17 ms 23808 KB Output is correct
34 Correct 18 ms 23808 KB Output is correct
35 Correct 18 ms 24192 KB Output is correct
36 Correct 17 ms 23936 KB Output is correct
37 Correct 16 ms 23936 KB Output is correct
38 Correct 16 ms 23936 KB Output is correct
39 Correct 18 ms 23936 KB Output is correct
40 Correct 17 ms 23936 KB Output is correct
41 Correct 17 ms 23936 KB Output is correct
42 Correct 18 ms 23936 KB Output is correct
43 Correct 17 ms 23936 KB Output is correct
44 Correct 18 ms 23936 KB Output is correct
45 Correct 18 ms 23936 KB Output is correct
46 Correct 18 ms 23936 KB Output is correct
47 Correct 19 ms 23936 KB Output is correct
48 Correct 18 ms 23936 KB Output is correct
49 Correct 16 ms 23936 KB Output is correct
50 Correct 17 ms 24064 KB Output is correct
51 Correct 16 ms 23936 KB Output is correct
52 Correct 17 ms 24064 KB Output is correct
53 Correct 17 ms 23936 KB Output is correct
54 Correct 17 ms 23928 KB Output is correct
55 Correct 17 ms 23936 KB Output is correct
56 Correct 17 ms 24064 KB Output is correct
57 Correct 17 ms 23936 KB Output is correct
58 Correct 17 ms 24064 KB Output is correct
59 Correct 16 ms 23808 KB Output is correct
60 Correct 18 ms 23808 KB Output is correct
61 Correct 17 ms 23808 KB Output is correct
62 Correct 18 ms 23808 KB Output is correct
63 Correct 17 ms 23808 KB Output is correct
64 Correct 17 ms 23808 KB Output is correct
65 Correct 114 ms 104268 KB Output is correct
66 Correct 116 ms 104260 KB Output is correct
67 Correct 116 ms 104140 KB Output is correct
68 Correct 114 ms 104276 KB Output is correct
69 Correct 116 ms 104268 KB Output is correct
70 Correct 113 ms 104256 KB Output is correct
71 Correct 113 ms 104140 KB Output is correct
72 Correct 112 ms 104136 KB Output is correct
73 Correct 114 ms 106180 KB Output is correct
74 Correct 112 ms 106212 KB Output is correct
75 Correct 112 ms 106308 KB Output is correct
76 Correct 115 ms 106312 KB Output is correct
77 Correct 112 ms 106188 KB Output is correct
78 Correct 115 ms 106188 KB Output is correct
79 Correct 117 ms 106184 KB Output is correct
80 Correct 116 ms 106188 KB Output is correct
81 Correct 116 ms 106184 KB Output is correct
82 Correct 117 ms 106192 KB Output is correct
83 Correct 116 ms 106188 KB Output is correct
84 Correct 118 ms 106184 KB Output is correct
85 Correct 116 ms 106188 KB Output is correct
86 Correct 117 ms 106184 KB Output is correct
87 Correct 117 ms 106180 KB Output is correct
88 Correct 119 ms 106184 KB Output is correct
89 Correct 115 ms 106184 KB Output is correct
90 Correct 116 ms 106188 KB Output is correct
91 Correct 126 ms 106316 KB Output is correct
92 Correct 124 ms 106188 KB Output is correct
93 Correct 118 ms 106196 KB Output is correct
94 Correct 123 ms 106184 KB Output is correct
95 Correct 127 ms 106184 KB Output is correct
96 Correct 124 ms 106308 KB Output is correct
97 Correct 120 ms 106188 KB Output is correct
98 Correct 131 ms 106284 KB Output is correct
99 Correct 126 ms 106316 KB Output is correct
100 Correct 120 ms 106180 KB Output is correct
101 Correct 128 ms 106176 KB Output is correct
102 Correct 126 ms 106188 KB Output is correct