Submission #332487

#TimeUsernameProblemLanguageResultExecution timeMemory
332487CaroLindaLamps (JOI19_lamps)C++14
100 / 100
71 ms66924 KiB
#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)

lamp.cpp: In function 'int main()':
lamp.cpp:13:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   13 |  scanf("%d", &n ) ;
      |  ~~~~~^~~~~~~~~~~
lamp.cpp:20:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   20 |  scanf("%s", A ) ;
      |  ~~~~~^~~~~~~~~~
lamp.cpp:21:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   21 |  scanf("%s", B ) ;
      |  ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...