답안 #250678

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
250678 2020-07-18T16:59:18 Z Blagojce Lamps (JOI19_lamps) C++11
100 / 100
50 ms 27988 KB
#include <bits/stdc++.h> 
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define st first
#define nd second
#define pq priority_queue
#define all(x) begin(x), end(x)
#include <time.h>
#include <cmath>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;

const int i_inf = 1e9;
const ll inf = 1e18;
const ll mod = 1000000007;
const ld eps = 1e-13;
const ld pi  = 3.14159265359;
 
mt19937 _rand(time(NULL));
clock_t timer = clock();
const int mxn = 4e6;
 
const ll A = 911382323;
const ll B = 972663749;
 
ll modpow(ll x, ll n){
	if(n == 0) return 1%mod;
	ll u = modpow(x, n/2);
	u = (u * u) % mod;
	if(n % 2) u = (u * x) % mod;
	return u;
}
ll inverse(ll x){
	return modpow(x, mod-2);
}
ll add(ll ans, ll val){
	ans = (ans + val) % mod;
	return ans;
}
ll mul(ll ans, ll val){
	ans = (ans * val) % mod;
	return ans;
}
ll sub(ll ans, ll val){
	ans = (ans - val) % mod;
	if(ans < 0) ans += mod;
	return ans;
}
ll _div(ll ans, ll val){
	ans = (ans * inverse(val)) % mod;
	return ans;
}
ll fakt[mxn];
ll bc(ll n, ll k){
	return (fakt[n]*inverse((fakt[k]*fakt[n-k])%mod))%mod;
}
ll sq(ll x){
	return x*x;
}
ll rsum(ll a, ll b){
	return (b-a+1)*(a+b)/2;
}
void prec(){
	fakt[0] = 1;
	fr(i, 1, mxn){
		fakt[i] = mul(fakt[i-1], i);
	}
}


int dp[mxn][6];
int trans[6][6];

void solve(){
	int val[6] = {0, 1, 2, 4, 5, 6};
	fr(i, 0, 6) fr(j, 0, 6) trans[i][j] = __builtin_popcount((val[i]|val[j])^val[i]);
		
	int n;
	cin >> n;
	string a, b;
	cin >> a;
	cin >> b;
	fr(i, 0, n+1)fr(j, 0, 6) dp[i][j] = i_inf;
	dp[0][0] = 0;
	
	fr(i, 1, n+1){
		if(a[i-1] == '1' && b[i-1] == '1'){
			fr(pr, 0, 6){
				dp[i][0] = min(dp[i][0], dp[i-1][pr] + trans[pr][0]); 
				dp[i][1] = min(dp[i][1], dp[i-1][pr] + trans[pr][1]);
				dp[i][5] = min(dp[i][5], dp[i-1][pr] + trans[pr][5]);
			}
		}
		else if(a[i-1] == '0' && b[i-1] == '0'){
			fr(pr, 0, 6){
				dp[i][0] = min(dp[i][0], dp[i-1][pr] + trans[pr][0]); 
				dp[i][2] = min(dp[i][2], dp[i-1][pr] + trans[pr][2]);
				dp[i][4] = min(dp[i][4], dp[i-1][pr] + trans[pr][4]);
			}
		}
		else if(a[i-1] == '1' && b[i-1] == '0'){
			fr(pr, 0, 6){
				dp[i][2] = min(dp[i][2], dp[i-1][pr] + trans[pr][2]); 
				dp[i][3] = min(dp[i][3], dp[i-1][pr] + trans[pr][3]);
				dp[i][4] = min(dp[i][4], dp[i-1][pr] + trans[pr][4]);
			}
		}
		else if(a[i-1] == '0' && b[i-1] == '1'){
			fr(pr, 0, 6){
				dp[i][1] = min(dp[i][1], dp[i-1][pr] + trans[pr][1]); 
				dp[i][3] = min(dp[i][3], dp[i-1][pr] + trans[pr][3]);
				dp[i][5] = min(dp[i][5], dp[i-1][pr] + trans[pr][5]);
			}
		}
	}
	
	int ans = i_inf;
	fr(i, 0, 6) ans = min(ans, dp[n][i]);
	cout<<ans<<endl;
	
	
	
}
 
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
23 Correct 0 ms 384 KB Output is correct
24 Correct 0 ms 384 KB Output is correct
25 Correct 0 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 0 ms 384 KB Output is correct
28 Correct 0 ms 384 KB Output is correct
29 Correct 0 ms 384 KB Output is correct
30 Correct 0 ms 384 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 0 ms 384 KB Output is correct
33 Correct 0 ms 384 KB Output is correct
34 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
23 Correct 0 ms 384 KB Output is correct
24 Correct 0 ms 384 KB Output is correct
25 Correct 0 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 0 ms 384 KB Output is correct
28 Correct 0 ms 384 KB Output is correct
29 Correct 0 ms 384 KB Output is correct
30 Correct 0 ms 384 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 0 ms 384 KB Output is correct
33 Correct 0 ms 384 KB Output is correct
34 Correct 0 ms 384 KB Output is correct
35 Correct 0 ms 384 KB Output is correct
36 Correct 0 ms 384 KB Output is correct
37 Correct 1 ms 384 KB Output is correct
38 Correct 0 ms 384 KB Output is correct
39 Correct 0 ms 384 KB Output is correct
40 Correct 0 ms 384 KB Output is correct
41 Correct 0 ms 384 KB Output is correct
42 Correct 0 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 1 ms 384 KB Output is correct
45 Correct 0 ms 384 KB Output is correct
46 Correct 0 ms 384 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 0 ms 384 KB Output is correct
49 Correct 1 ms 384 KB Output is correct
50 Correct 1 ms 384 KB Output is correct
51 Correct 0 ms 384 KB Output is correct
52 Correct 1 ms 384 KB Output is correct
53 Correct 0 ms 384 KB Output is correct
54 Correct 1 ms 384 KB Output is correct
55 Correct 0 ms 384 KB Output is correct
56 Correct 0 ms 384 KB Output is correct
57 Correct 1 ms 384 KB Output is correct
58 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 32 ms 25940 KB Output is correct
8 Correct 36 ms 27852 KB Output is correct
9 Correct 33 ms 27860 KB Output is correct
10 Correct 48 ms 27852 KB Output is correct
11 Correct 33 ms 27860 KB Output is correct
12 Correct 42 ms 27852 KB Output is correct
13 Correct 35 ms 27860 KB Output is correct
14 Correct 35 ms 27852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
23 Correct 0 ms 384 KB Output is correct
24 Correct 0 ms 384 KB Output is correct
25 Correct 0 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 0 ms 384 KB Output is correct
28 Correct 0 ms 384 KB Output is correct
29 Correct 0 ms 384 KB Output is correct
30 Correct 0 ms 384 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 0 ms 384 KB Output is correct
33 Correct 0 ms 384 KB Output is correct
34 Correct 0 ms 384 KB Output is correct
35 Correct 0 ms 384 KB Output is correct
36 Correct 0 ms 384 KB Output is correct
37 Correct 1 ms 384 KB Output is correct
38 Correct 0 ms 384 KB Output is correct
39 Correct 0 ms 384 KB Output is correct
40 Correct 0 ms 384 KB Output is correct
41 Correct 0 ms 384 KB Output is correct
42 Correct 0 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 1 ms 384 KB Output is correct
45 Correct 0 ms 384 KB Output is correct
46 Correct 0 ms 384 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 0 ms 384 KB Output is correct
49 Correct 1 ms 384 KB Output is correct
50 Correct 1 ms 384 KB Output is correct
51 Correct 0 ms 384 KB Output is correct
52 Correct 1 ms 384 KB Output is correct
53 Correct 0 ms 384 KB Output is correct
54 Correct 1 ms 384 KB Output is correct
55 Correct 0 ms 384 KB Output is correct
56 Correct 0 ms 384 KB Output is correct
57 Correct 1 ms 384 KB Output is correct
58 Correct 0 ms 384 KB Output is correct
59 Correct 0 ms 384 KB Output is correct
60 Correct 0 ms 384 KB Output is correct
61 Correct 0 ms 384 KB Output is correct
62 Correct 0 ms 384 KB Output is correct
63 Correct 1 ms 384 KB Output is correct
64 Correct 0 ms 384 KB Output is correct
65 Correct 32 ms 25940 KB Output is correct
66 Correct 36 ms 27852 KB Output is correct
67 Correct 33 ms 27860 KB Output is correct
68 Correct 48 ms 27852 KB Output is correct
69 Correct 33 ms 27860 KB Output is correct
70 Correct 42 ms 27852 KB Output is correct
71 Correct 35 ms 27860 KB Output is correct
72 Correct 35 ms 27852 KB Output is correct
73 Correct 34 ms 27860 KB Output is correct
74 Correct 34 ms 27860 KB Output is correct
75 Correct 35 ms 27860 KB Output is correct
76 Correct 38 ms 27860 KB Output is correct
77 Correct 33 ms 27988 KB Output is correct
78 Correct 32 ms 27988 KB Output is correct
79 Correct 34 ms 27860 KB Output is correct
80 Correct 34 ms 27860 KB Output is correct
81 Correct 34 ms 27860 KB Output is correct
82 Correct 37 ms 27860 KB Output is correct
83 Correct 37 ms 27860 KB Output is correct
84 Correct 40 ms 27860 KB Output is correct
85 Correct 41 ms 27860 KB Output is correct
86 Correct 37 ms 27860 KB Output is correct
87 Correct 39 ms 27976 KB Output is correct
88 Correct 38 ms 27860 KB Output is correct
89 Correct 37 ms 27860 KB Output is correct
90 Correct 41 ms 27852 KB Output is correct
91 Correct 41 ms 27860 KB Output is correct
92 Correct 45 ms 27860 KB Output is correct
93 Correct 46 ms 27884 KB Output is correct
94 Correct 46 ms 27860 KB Output is correct
95 Correct 42 ms 27860 KB Output is correct
96 Correct 43 ms 27860 KB Output is correct
97 Correct 50 ms 27860 KB Output is correct
98 Correct 45 ms 27976 KB Output is correct
99 Correct 47 ms 27860 KB Output is correct
100 Correct 42 ms 27860 KB Output is correct
101 Correct 43 ms 27860 KB Output is correct
102 Correct 41 ms 27972 KB Output is correct