답안 #919111

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
919111 2024-01-31T10:10:48 Z ThylOne Lamps (JOI19_lamps) C++14
0 / 100
1000 ms 160864 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]){
                ans = min(ans,((s2==i || i==RIEN)?0:1)+solve(pos+1,s1,i));
            }
        }
        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,s1,i));
            }
        }
        
    for(int i = RIEN;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 15 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 64288 KB Output is correct
6 Correct 14 ms 64092 KB Output is correct
7 Correct 16 ms 64092 KB Output is correct
8 Correct 13 ms 64088 KB Output is correct
9 Correct 14 ms 64088 KB Output is correct
10 Correct 14 ms 64212 KB Output is correct
11 Correct 14 ms 64092 KB Output is correct
12 Correct 15 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 14 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 64088 KB Output is correct
21 Correct 14 ms 64088 KB Output is correct
22 Correct 14 ms 64092 KB Output is correct
23 Correct 13 ms 64088 KB Output is correct
24 Correct 14 ms 64092 KB Output is correct
25 Correct 14 ms 64088 KB Output is correct
26 Incorrect 14 ms 64088 KB Output isn't correct
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 64088 KB Output is correct
2 Correct 15 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 64288 KB Output is correct
6 Correct 14 ms 64092 KB Output is correct
7 Correct 16 ms 64092 KB Output is correct
8 Correct 13 ms 64088 KB Output is correct
9 Correct 14 ms 64088 KB Output is correct
10 Correct 14 ms 64212 KB Output is correct
11 Correct 14 ms 64092 KB Output is correct
12 Correct 15 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 14 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 64088 KB Output is correct
21 Correct 14 ms 64088 KB Output is correct
22 Correct 14 ms 64092 KB Output is correct
23 Correct 13 ms 64088 KB Output is correct
24 Correct 14 ms 64092 KB Output is correct
25 Correct 14 ms 64088 KB Output is correct
26 Incorrect 14 ms 64088 KB Output isn't correct
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 64088 KB Output is correct
2 Correct 14 ms 64212 KB Output is correct
3 Correct 14 ms 64088 KB Output is correct
4 Correct 14 ms 64092 KB Output is correct
5 Correct 13 ms 64344 KB Output is correct
6 Correct 14 ms 64176 KB Output is correct
7 Execution timed out 1056 ms 160864 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 64088 KB Output is correct
2 Correct 15 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 64288 KB Output is correct
6 Correct 14 ms 64092 KB Output is correct
7 Correct 16 ms 64092 KB Output is correct
8 Correct 13 ms 64088 KB Output is correct
9 Correct 14 ms 64088 KB Output is correct
10 Correct 14 ms 64212 KB Output is correct
11 Correct 14 ms 64092 KB Output is correct
12 Correct 15 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 14 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 64088 KB Output is correct
21 Correct 14 ms 64088 KB Output is correct
22 Correct 14 ms 64092 KB Output is correct
23 Correct 13 ms 64088 KB Output is correct
24 Correct 14 ms 64092 KB Output is correct
25 Correct 14 ms 64088 KB Output is correct
26 Incorrect 14 ms 64088 KB Output isn't correct
27 Halted 0 ms 0 KB -