답안 #919116

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
919116 2024-01-31T10:19:15 Z ThylOne Lamps (JOI19_lamps) C++14
10 / 100
738 ms 161268 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]){
                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 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 16 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 13 ms 64088 KB Output is correct
6 Correct 13 ms 64088 KB Output is correct
7 Correct 14 ms 64092 KB Output is correct
8 Correct 14 ms 64092 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 64088 KB Output is correct
12 Correct 14 ms 64092 KB Output is correct
13 Correct 14 ms 64088 KB Output is correct
14 Correct 14 ms 64088 KB Output is correct
15 Correct 14 ms 64088 KB Output is correct
16 Correct 14 ms 64088 KB Output is correct
17 Correct 14 ms 64088 KB Output is correct
18 Correct 14 ms 64088 KB Output is correct
19 Correct 15 ms 64092 KB Output is correct
20 Correct 14 ms 64092 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 15 ms 64088 KB Output is correct
25 Correct 14 ms 64088 KB Output is correct
26 Correct 14 ms 64088 KB Output is correct
27 Correct 14 ms 64160 KB Output is correct
28 Correct 15 ms 64088 KB Output is correct
29 Correct 15 ms 64088 KB Output is correct
30 Correct 14 ms 64092 KB Output is correct
31 Correct 15 ms 64344 KB Output is correct
32 Correct 14 ms 64292 KB Output is correct
33 Correct 14 ms 64088 KB Output is correct
34 Correct 15 ms 64088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 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 13 ms 64088 KB Output is correct
6 Correct 13 ms 64088 KB Output is correct
7 Correct 14 ms 64092 KB Output is correct
8 Correct 14 ms 64092 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 64088 KB Output is correct
12 Correct 14 ms 64092 KB Output is correct
13 Correct 14 ms 64088 KB Output is correct
14 Correct 14 ms 64088 KB Output is correct
15 Correct 14 ms 64088 KB Output is correct
16 Correct 14 ms 64088 KB Output is correct
17 Correct 14 ms 64088 KB Output is correct
18 Correct 14 ms 64088 KB Output is correct
19 Correct 15 ms 64092 KB Output is correct
20 Correct 14 ms 64092 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 15 ms 64088 KB Output is correct
25 Correct 14 ms 64088 KB Output is correct
26 Correct 14 ms 64088 KB Output is correct
27 Correct 14 ms 64160 KB Output is correct
28 Correct 15 ms 64088 KB Output is correct
29 Correct 15 ms 64088 KB Output is correct
30 Correct 14 ms 64092 KB Output is correct
31 Correct 15 ms 64344 KB Output is correct
32 Correct 14 ms 64292 KB Output is correct
33 Correct 14 ms 64088 KB Output is correct
34 Correct 15 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 16 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 -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 64088 KB Output is correct
2 Correct 14 ms 64092 KB Output is correct
3 Correct 14 ms 64084 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 705 ms 161024 KB Output is correct
8 Correct 738 ms 161024 KB Output is correct
9 Correct 738 ms 161028 KB Output is correct
10 Correct 734 ms 161024 KB Output is correct
11 Correct 735 ms 161024 KB Output is correct
12 Correct 631 ms 161268 KB Output is correct
13 Correct 697 ms 161084 KB Output is correct
14 Correct 709 ms 161008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 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 13 ms 64088 KB Output is correct
6 Correct 13 ms 64088 KB Output is correct
7 Correct 14 ms 64092 KB Output is correct
8 Correct 14 ms 64092 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 64088 KB Output is correct
12 Correct 14 ms 64092 KB Output is correct
13 Correct 14 ms 64088 KB Output is correct
14 Correct 14 ms 64088 KB Output is correct
15 Correct 14 ms 64088 KB Output is correct
16 Correct 14 ms 64088 KB Output is correct
17 Correct 14 ms 64088 KB Output is correct
18 Correct 14 ms 64088 KB Output is correct
19 Correct 15 ms 64092 KB Output is correct
20 Correct 14 ms 64092 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 15 ms 64088 KB Output is correct
25 Correct 14 ms 64088 KB Output is correct
26 Correct 14 ms 64088 KB Output is correct
27 Correct 14 ms 64160 KB Output is correct
28 Correct 15 ms 64088 KB Output is correct
29 Correct 15 ms 64088 KB Output is correct
30 Correct 14 ms 64092 KB Output is correct
31 Correct 15 ms 64344 KB Output is correct
32 Correct 14 ms 64292 KB Output is correct
33 Correct 14 ms 64088 KB Output is correct
34 Correct 15 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 16 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 -