답안 #877349

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
877349 2023-11-23T07:40:29 Z winter0101 Lamps (JOI19_lamps) C++14
100 / 100
85 ms 51500 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][10];
int a[maxn],b[maxn];
vector<int> state[10]={{0},{1},{2},{3},{1,2},{1,3},{2,1},{2,3},{3,1},{3,2}};
int nxt[2][10];
int cost[10][10];
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,1){
    for1(j,0,9){
    int ni=i;
    for(auto v:state[j]){
    if (v==0)continue;
    if (v==1)ni=1;
    if (v==2)ni=0;
    if (v==3)ni=1-ni;
    }
    nxt[i][j]=ni;
    }
    }
    for1(i,0,9){
    for1(j,0,9){
    if (i==0)cost[i][j]=sz(state[j]);
    if (j==0)cost[i][j]=0;
    if (i!=0&&j!=0&&i!=j){
    if (sz(state[i])==1&&sz(state[j])==1){
    cost[i][j]=1;
    }
    if (sz(state[i])==1&&sz(state[j])==2){
    bool fl=1;
    for (auto v:state[j]){
    if (v==state[i][0]){
    fl=0;
    break;
    }
    }
    cost[i][j]=fl+1;
    }
    if (sz(state[i])==2&&sz(state[j])==1){
    bool fl=1;
    for (auto v:state[i]){
    if (v==state[j][0]){
    fl=0;
    break;
    }
    }
    cost[i][j]=fl;
    }
    if (sz(state[i])==2&&sz(state[j])==2){
    cost[i][j]=1;
    }
    }
    }
    }
    for1(i,0,n){
    for1(j,0,9){
    f[i][j]=n+1;
    }
    }
    f[0][0]=0;
    for1(i,1,n){
    for1(j,0,9){
    if (nxt[a[i]][j]==b[i]){
    for1(k,0,9){
    f[i][j]=min(f[i][j],f[i-1][k]+cost[k][j]);
    }
    }
    }
    }
    int ans=n+1;
    for1(i,0,9)ans=min(ans,f[n][i]);
    cout<<ans;
    //for1(i,0,9)for1(j,0,9)cout<<i<<" "<<j<<" "<<cost[i][j]<<'\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4560 KB Output is correct
2 Correct 1 ms 4440 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 4444 KB Output is correct
8 Correct 0 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 4444 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 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 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 4564 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 4560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4560 KB Output is correct
2 Correct 1 ms 4440 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 4444 KB Output is correct
8 Correct 0 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 4444 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 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 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 4564 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 4560 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 4444 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 4444 KB Output is correct
43 Correct 1 ms 4444 KB Output is correct
44 Correct 1 ms 4588 KB Output is correct
45 Correct 1 ms 4444 KB Output is correct
46 Correct 1 ms 4444 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 4444 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 2396 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 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 63 ms 44920 KB Output is correct
8 Correct 59 ms 49160 KB Output is correct
9 Correct 60 ms 49160 KB Output is correct
10 Correct 63 ms 49372 KB Output is correct
11 Correct 58 ms 49152 KB Output is correct
12 Correct 58 ms 49148 KB Output is correct
13 Correct 59 ms 49068 KB Output is correct
14 Correct 62 ms 49232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4560 KB Output is correct
2 Correct 1 ms 4440 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 4444 KB Output is correct
8 Correct 0 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 4444 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 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 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 4564 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 4560 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 4444 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 4444 KB Output is correct
43 Correct 1 ms 4444 KB Output is correct
44 Correct 1 ms 4588 KB Output is correct
45 Correct 1 ms 4444 KB Output is correct
46 Correct 1 ms 4444 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 4444 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 2396 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 2396 KB Output is correct
64 Correct 1 ms 2396 KB Output is correct
65 Correct 63 ms 44920 KB Output is correct
66 Correct 59 ms 49160 KB Output is correct
67 Correct 60 ms 49160 KB Output is correct
68 Correct 63 ms 49372 KB Output is correct
69 Correct 58 ms 49152 KB Output is correct
70 Correct 58 ms 49148 KB Output is correct
71 Correct 59 ms 49068 KB Output is correct
72 Correct 62 ms 49232 KB Output is correct
73 Correct 60 ms 48896 KB Output is correct
74 Correct 66 ms 51200 KB Output is correct
75 Correct 58 ms 51208 KB Output is correct
76 Correct 60 ms 51196 KB Output is correct
77 Correct 61 ms 51500 KB Output is correct
78 Correct 60 ms 51200 KB Output is correct
79 Correct 62 ms 51200 KB Output is correct
80 Correct 59 ms 51208 KB Output is correct
81 Correct 59 ms 51204 KB Output is correct
82 Correct 63 ms 51208 KB Output is correct
83 Correct 67 ms 51200 KB Output is correct
84 Correct 66 ms 51160 KB Output is correct
85 Correct 71 ms 51200 KB Output is correct
86 Correct 67 ms 51196 KB Output is correct
87 Correct 67 ms 51208 KB Output is correct
88 Correct 67 ms 51196 KB Output is correct
89 Correct 72 ms 51116 KB Output is correct
90 Correct 69 ms 51200 KB Output is correct
91 Correct 73 ms 51120 KB Output is correct
92 Correct 72 ms 51160 KB Output is correct
93 Correct 85 ms 51196 KB Output is correct
94 Correct 74 ms 51196 KB Output is correct
95 Correct 75 ms 51344 KB Output is correct
96 Correct 76 ms 51200 KB Output is correct
97 Correct 74 ms 51160 KB Output is correct
98 Correct 73 ms 51196 KB Output is correct
99 Correct 74 ms 51220 KB Output is correct
100 Correct 79 ms 51200 KB Output is correct
101 Correct 74 ms 51192 KB Output is correct
102 Correct 78 ms 51196 KB Output is correct