답안 #877380

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
877380 2023-11-23T08:00:20 Z winter0101 Lamps (JOI19_lamps) C++14
100 / 100
91 ms 35792 KB
#include<bits/stdc++.h>
using namespace std;
#define all(fl) fl.begin(),fl.end()
#define pb push_back
#define fi first
#define se second
#define for1(i,j,k) for(int i=j;i<=k;i++)
#define for2(i,j,k) for(int i=j;i>=k;i--)
#define for3(i,j,k,l) for(int i=j;i<=k;i+=l)
#define lb lower_bound
#define ub upper_bound
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define pli pair<long long,int>
#define gcd __gcd
#define lcm(x,y) x*y/__gcd(x,y)
#define pil pair<int,long long>
const int maxn=1e6+9;
int f[maxn][3][2];
int a[maxn],b[maxn];
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("temp.INP","r",stdin);
    //freopen("temp.OUT","w",stdout);
    int n;
    cin>>n;
    string s,t;
    cin>>s>>t;
    s=" "+s;
    t=" "+t;
    for1(i,1,n){
    if (s[i]=='1')a[i]=1;
    if (t[i]=='1')b[i]=1;
    }
    for1(i,0,n){
    for1(j,0,2){
    for1(k,0,1){
    f[i][j][k]=n+1;
    }
    }
    }
    f[0][0][0]=0;
    //turn on/off ? then toggle later
    //1 on 2 off
    for1(i,1,n){
    for1(newj,0,2){
    for1(newk,0,1){
    for1(j,0,2){
    for1(k,0,1){
    int cost=(f[i-1][j][k]+(j!=newj&&newj!=0)+(k!=newk&&newk==1));
    int newa=a[i];
    if (newj==1)newa=1;
    if (newj==2)newa=0;
    if (newk==1)newa=1-newa;
    if (newa!=b[i])continue;
    f[i][newj][newk]=min(f[i][newj][newk],cost);
    }
    }
    }
    }
    }
    int ans=n+1;
    for1(j,0,2)for1(k,0,1)ans=min(ans,f[n][j][k]);
    cout<<ans;

}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4568 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4572 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4440 KB Output is correct
20 Correct 1 ms 4440 KB Output is correct
21 Correct 1 ms 4448 KB Output is correct
22 Correct 1 ms 4448 KB Output is correct
23 Correct 1 ms 4448 KB Output is correct
24 Correct 1 ms 4448 KB Output is correct
25 Correct 1 ms 4448 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4568 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4572 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4440 KB Output is correct
20 Correct 1 ms 4440 KB Output is correct
21 Correct 1 ms 4448 KB Output is correct
22 Correct 1 ms 4448 KB Output is correct
23 Correct 1 ms 4448 KB Output is correct
24 Correct 1 ms 4448 KB Output is correct
25 Correct 1 ms 4448 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 1 ms 4444 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 1 ms 4440 KB Output is correct
39 Correct 1 ms 4444 KB Output is correct
40 Correct 1 ms 4444 KB Output is correct
41 Correct 1 ms 4448 KB Output is correct
42 Correct 1 ms 4440 KB Output is correct
43 Correct 1 ms 4440 KB Output is correct
44 Correct 2 ms 4440 KB Output is correct
45 Correct 1 ms 4444 KB Output is correct
46 Correct 1 ms 4560 KB Output is correct
47 Correct 1 ms 4444 KB Output is correct
48 Correct 1 ms 4444 KB Output is correct
49 Correct 1 ms 4444 KB Output is correct
50 Correct 1 ms 4444 KB Output is correct
51 Correct 1 ms 4444 KB Output is correct
52 Correct 1 ms 4588 KB Output is correct
53 Correct 1 ms 4444 KB Output is correct
54 Correct 1 ms 4444 KB Output is correct
55 Correct 1 ms 4444 KB Output is correct
56 Correct 1 ms 4444 KB Output is correct
57 Correct 1 ms 4444 KB Output is correct
58 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2512 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 80 ms 29188 KB Output is correct
8 Correct 73 ms 33532 KB Output is correct
9 Correct 73 ms 33532 KB Output is correct
10 Correct 77 ms 33540 KB Output is correct
11 Correct 72 ms 33544 KB Output is correct
12 Correct 79 ms 33540 KB Output is correct
13 Correct 73 ms 33540 KB Output is correct
14 Correct 74 ms 33540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4568 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4572 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4440 KB Output is correct
20 Correct 1 ms 4440 KB Output is correct
21 Correct 1 ms 4448 KB Output is correct
22 Correct 1 ms 4448 KB Output is correct
23 Correct 1 ms 4448 KB Output is correct
24 Correct 1 ms 4448 KB Output is correct
25 Correct 1 ms 4448 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 1 ms 4444 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 1 ms 4440 KB Output is correct
39 Correct 1 ms 4444 KB Output is correct
40 Correct 1 ms 4444 KB Output is correct
41 Correct 1 ms 4448 KB Output is correct
42 Correct 1 ms 4440 KB Output is correct
43 Correct 1 ms 4440 KB Output is correct
44 Correct 2 ms 4440 KB Output is correct
45 Correct 1 ms 4444 KB Output is correct
46 Correct 1 ms 4560 KB Output is correct
47 Correct 1 ms 4444 KB Output is correct
48 Correct 1 ms 4444 KB Output is correct
49 Correct 1 ms 4444 KB Output is correct
50 Correct 1 ms 4444 KB Output is correct
51 Correct 1 ms 4444 KB Output is correct
52 Correct 1 ms 4588 KB Output is correct
53 Correct 1 ms 4444 KB Output is correct
54 Correct 1 ms 4444 KB Output is correct
55 Correct 1 ms 4444 KB Output is correct
56 Correct 1 ms 4444 KB Output is correct
57 Correct 1 ms 4444 KB Output is correct
58 Correct 1 ms 4444 KB Output is correct
59 Correct 1 ms 2392 KB Output is correct
60 Correct 1 ms 2396 KB Output is correct
61 Correct 1 ms 2396 KB Output is correct
62 Correct 1 ms 2396 KB Output is correct
63 Correct 1 ms 2512 KB Output is correct
64 Correct 0 ms 2396 KB Output is correct
65 Correct 80 ms 29188 KB Output is correct
66 Correct 73 ms 33532 KB Output is correct
67 Correct 73 ms 33532 KB Output is correct
68 Correct 77 ms 33540 KB Output is correct
69 Correct 72 ms 33544 KB Output is correct
70 Correct 79 ms 33540 KB Output is correct
71 Correct 73 ms 33540 KB Output is correct
72 Correct 74 ms 33540 KB Output is correct
73 Correct 77 ms 33496 KB Output is correct
74 Correct 74 ms 35572 KB Output is correct
75 Correct 74 ms 35580 KB Output is correct
76 Correct 74 ms 35652 KB Output is correct
77 Correct 73 ms 35576 KB Output is correct
78 Correct 73 ms 35580 KB Output is correct
79 Correct 74 ms 35588 KB Output is correct
80 Correct 73 ms 35588 KB Output is correct
81 Correct 72 ms 35484 KB Output is correct
82 Correct 78 ms 35496 KB Output is correct
83 Correct 78 ms 35636 KB Output is correct
84 Correct 79 ms 35456 KB Output is correct
85 Correct 86 ms 35584 KB Output is correct
86 Correct 81 ms 35564 KB Output is correct
87 Correct 78 ms 35588 KB Output is correct
88 Correct 78 ms 35580 KB Output is correct
89 Correct 83 ms 35580 KB Output is correct
90 Correct 79 ms 35596 KB Output is correct
91 Correct 80 ms 35652 KB Output is correct
92 Correct 84 ms 35472 KB Output is correct
93 Correct 87 ms 35580 KB Output is correct
94 Correct 86 ms 35576 KB Output is correct
95 Correct 89 ms 35572 KB Output is correct
96 Correct 85 ms 35584 KB Output is correct
97 Correct 87 ms 35576 KB Output is correct
98 Correct 86 ms 35568 KB Output is correct
99 Correct 86 ms 35792 KB Output is correct
100 Correct 91 ms 35656 KB Output is correct
101 Correct 86 ms 35536 KB Output is correct
102 Correct 89 ms 35544 KB Output is correct