# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
332487 | CaroLinda | Lamps (JOI19_lamps) | C++14 | 71 ms | 66924 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
const int MAX = 1e6+10 ;
using namespace std ;
char A[MAX], B[MAX] ;
int dp[MAX][4][4] ;
int main()
{
int n ;
scanf("%d", &n ) ;
//0 = seta tudo pra 0
//1 = seta tudo pra 1
//2 = switch
//3 = nao tem nada rolando
scanf("%s", A ) ;
scanf("%s", B ) ;
for(int i = n-1 ; i >= 0 ; i-- )
for(int j = 2 ; j >= 0 ; j-- )
for(int g = 0 ; g < 2 ; g++ )
{
int val1 = A[i] - '0' ;
int val2 = B[i] - '0' ;
int &ptr = dp[i][j][g] ;
ptr = n+1 ;
//fecho o intervalo
if( j < 2 ) ptr = min(ptr, dp[i][2][g] ) ;
if(j == 0 )
ptr = min(ptr, dp[i+1][j][ val2 != 0 ] + ( (val2!=0)&(!g) ) ) ;
if(j == 1 )
ptr = min(ptr, dp[i+1][j][val2!=1] + ( (val2!=1)&(!g) ) ) ;
if(j == 2 )
{
//nao faco nada
ptr = dp[i+1][2][ val1 != val2 ] + ( (val1 != val2 )&(!g) ) ;
//faco 0
ptr = min(ptr, dp[i+1][0][ val2 != 0] + ( (val2 != 0 )&(!g) ) + 1 ) ;
//faco 1
ptr = min(ptr, dp[i+1][1][val2!=1] + ((val2!=1)&(!g) ) + 1 ) ;
}
}
printf("%d\n", dp[0][2][0] ) ;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |