Submission #919119

# Submission time Handle Problem Language Result Execution time Memory
919119 2024-01-31T10:29:06 Z ThylOne Lamps (JOI19_lamps) C++14
10 / 100
609 ms 161032 KB
#include<bits/stdc++.h>
using namespace std;
const int maxiN = 1000000;
int n;
bool a[maxiN],b[maxiN];
const int RIEN = 0;
const int ONE = 1;
const int ZERO = 2;
const int FLIP = 3;
bool apply(bool v,int s){
    if(s==ONE)return 1;
    if(s==ZERO)return 0;
    if(s==FLIP)return !v;
    if(s==RIEN)return v;
}
int dp[maxiN][4][4];
int solve(int pos,int s1,int s2){
    
    if(pos==n)return 0;
    if(dp[pos][s1][s2]!=-1)return dp[pos][s1][s2];
    int ans = n+1;
    //On change que le dernier inter
    
    for(int i=RIEN;i<=FLIP;i++){
        bool p = apply(apply(a[pos],s1),i);
        if(p==b[pos] && i!=s1){
            ans = min(ans,((s2==i || i==RIEN)?0:1)+solve(pos+1,s1,i));
        }
    }
    //On retire le premier
    for(int i=RIEN;i<=FLIP;i++){
        bool p = apply(apply(a[pos],s2),i);
        if(p==b[pos] && i!=s2){
            ans = min(ans,((i==RIEN)?0:1)+solve(pos+1,s2,i));
        }
    }
    //On retire tout
    for(int i = RIEN+1;i<=FLIP;i++){
        for(int j=RIEN;j<=FLIP;j++){
            bool p = apply(apply(a[pos],i),j);
            if(p==b[pos] && i!=j){
                int malus = (i!=RIEN) + (j!=RIEN);
                ans = min(ans,malus+solve(pos+1,i,j));
            }
        }
    }
    if(a[pos]==b[pos]){
        ans = min(ans,solve(pos+1,RIEN,RIEN));
    }
    return dp[pos][s1][s2]=ans;
}
signed main(){
    string f,t;
    cin>>n;
    cin>>f>>t;
    for(int i = 0;i<n;i++){
        a[i] = (f[i]=='1');
        b[i] = (t[i]=='1');
    }
    for(int i = 0;i<maxiN;i++){
        for(int c=0;c<4;c++){
            for(int g=0;g<4;g++){
                dp[i][c][g]=-1;
            }
        }
    }
    cout<<solve(0,RIEN,RIEN)<<endl;
    return 0;
}

Compilation message

lamp.cpp: In function 'bool apply(bool, int)':
lamp.cpp:15:1: warning: control reaches end of non-void function [-Wreturn-type]
   15 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 15 ms 64088 KB Output is correct
2 Correct 14 ms 64088 KB Output is correct
3 Correct 14 ms 64088 KB Output is correct
4 Correct 14 ms 64088 KB Output is correct
5 Correct 14 ms 64088 KB Output is correct
6 Correct 13 ms 64088 KB Output is correct
7 Correct 14 ms 64088 KB Output is correct
8 Correct 14 ms 64088 KB Output is correct
9 Correct 14 ms 64088 KB Output is correct
10 Correct 14 ms 64088 KB Output is correct
11 Correct 14 ms 64192 KB Output is correct
12 Correct 14 ms 64088 KB Output is correct
13 Correct 14 ms 64088 KB Output is correct
14 Correct 14 ms 64092 KB Output is correct
15 Correct 14 ms 64088 KB Output is correct
16 Correct 14 ms 64088 KB Output is correct
17 Correct 13 ms 64088 KB Output is correct
18 Correct 14 ms 64088 KB Output is correct
19 Correct 14 ms 64088 KB Output is correct
20 Correct 14 ms 64212 KB Output is correct
21 Correct 14 ms 64088 KB Output is correct
22 Correct 14 ms 64088 KB Output is correct
23 Correct 14 ms 64088 KB Output is correct
24 Correct 14 ms 64088 KB Output is correct
25 Correct 15 ms 64088 KB Output is correct
26 Correct 14 ms 64088 KB Output is correct
27 Correct 14 ms 64088 KB Output is correct
28 Correct 14 ms 64088 KB Output is correct
29 Correct 14 ms 64088 KB Output is correct
30 Correct 14 ms 64088 KB Output is correct
31 Correct 14 ms 64088 KB Output is correct
32 Correct 14 ms 64092 KB Output is correct
33 Correct 14 ms 64088 KB Output is correct
34 Correct 14 ms 64088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 64088 KB Output is correct
2 Correct 14 ms 64088 KB Output is correct
3 Correct 14 ms 64088 KB Output is correct
4 Correct 14 ms 64088 KB Output is correct
5 Correct 14 ms 64088 KB Output is correct
6 Correct 13 ms 64088 KB Output is correct
7 Correct 14 ms 64088 KB Output is correct
8 Correct 14 ms 64088 KB Output is correct
9 Correct 14 ms 64088 KB Output is correct
10 Correct 14 ms 64088 KB Output is correct
11 Correct 14 ms 64192 KB Output is correct
12 Correct 14 ms 64088 KB Output is correct
13 Correct 14 ms 64088 KB Output is correct
14 Correct 14 ms 64092 KB Output is correct
15 Correct 14 ms 64088 KB Output is correct
16 Correct 14 ms 64088 KB Output is correct
17 Correct 13 ms 64088 KB Output is correct
18 Correct 14 ms 64088 KB Output is correct
19 Correct 14 ms 64088 KB Output is correct
20 Correct 14 ms 64212 KB Output is correct
21 Correct 14 ms 64088 KB Output is correct
22 Correct 14 ms 64088 KB Output is correct
23 Correct 14 ms 64088 KB Output is correct
24 Correct 14 ms 64088 KB Output is correct
25 Correct 15 ms 64088 KB Output is correct
26 Correct 14 ms 64088 KB Output is correct
27 Correct 14 ms 64088 KB Output is correct
28 Correct 14 ms 64088 KB Output is correct
29 Correct 14 ms 64088 KB Output is correct
30 Correct 14 ms 64088 KB Output is correct
31 Correct 14 ms 64088 KB Output is correct
32 Correct 14 ms 64092 KB Output is correct
33 Correct 14 ms 64088 KB Output is correct
34 Correct 14 ms 64088 KB Output is correct
35 Correct 15 ms 64344 KB Output is correct
36 Correct 15 ms 64344 KB Output is correct
37 Correct 15 ms 64344 KB Output is correct
38 Correct 15 ms 64344 KB Output is correct
39 Correct 15 ms 64348 KB Output is correct
40 Incorrect 15 ms 64344 KB Output isn't correct
41 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 64088 KB Output is correct
2 Correct 14 ms 64088 KB Output is correct
3 Correct 14 ms 64088 KB Output is correct
4 Correct 14 ms 64088 KB Output is correct
5 Correct 14 ms 64088 KB Output is correct
6 Correct 14 ms 64088 KB Output is correct
7 Correct 526 ms 160828 KB Output is correct
8 Correct 609 ms 161020 KB Output is correct
9 Correct 603 ms 161024 KB Output is correct
10 Correct 592 ms 161032 KB Output is correct
11 Correct 582 ms 160832 KB Output is correct
12 Correct 578 ms 160832 KB Output is correct
13 Correct 591 ms 160828 KB Output is correct
14 Correct 573 ms 160832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 64088 KB Output is correct
2 Correct 14 ms 64088 KB Output is correct
3 Correct 14 ms 64088 KB Output is correct
4 Correct 14 ms 64088 KB Output is correct
5 Correct 14 ms 64088 KB Output is correct
6 Correct 13 ms 64088 KB Output is correct
7 Correct 14 ms 64088 KB Output is correct
8 Correct 14 ms 64088 KB Output is correct
9 Correct 14 ms 64088 KB Output is correct
10 Correct 14 ms 64088 KB Output is correct
11 Correct 14 ms 64192 KB Output is correct
12 Correct 14 ms 64088 KB Output is correct
13 Correct 14 ms 64088 KB Output is correct
14 Correct 14 ms 64092 KB Output is correct
15 Correct 14 ms 64088 KB Output is correct
16 Correct 14 ms 64088 KB Output is correct
17 Correct 13 ms 64088 KB Output is correct
18 Correct 14 ms 64088 KB Output is correct
19 Correct 14 ms 64088 KB Output is correct
20 Correct 14 ms 64212 KB Output is correct
21 Correct 14 ms 64088 KB Output is correct
22 Correct 14 ms 64088 KB Output is correct
23 Correct 14 ms 64088 KB Output is correct
24 Correct 14 ms 64088 KB Output is correct
25 Correct 15 ms 64088 KB Output is correct
26 Correct 14 ms 64088 KB Output is correct
27 Correct 14 ms 64088 KB Output is correct
28 Correct 14 ms 64088 KB Output is correct
29 Correct 14 ms 64088 KB Output is correct
30 Correct 14 ms 64088 KB Output is correct
31 Correct 14 ms 64088 KB Output is correct
32 Correct 14 ms 64092 KB Output is correct
33 Correct 14 ms 64088 KB Output is correct
34 Correct 14 ms 64088 KB Output is correct
35 Correct 15 ms 64344 KB Output is correct
36 Correct 15 ms 64344 KB Output is correct
37 Correct 15 ms 64344 KB Output is correct
38 Correct 15 ms 64344 KB Output is correct
39 Correct 15 ms 64348 KB Output is correct
40 Incorrect 15 ms 64344 KB Output isn't correct
41 Halted 0 ms 0 KB -