Submission #376512

#TimeUsernameProblemLanguageResultExecution timeMemory
376512Sparky_09Lamps (JOI19_lamps)C++17
100 / 100
53 ms16108 KiB
#include "bits/stdc++.h"
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define trav(a, x) for(auto& a : x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;

int rd() {
	int result = 0;
	char ch;
	ch = getchar();
	while(ch < '0' || ch > '9') ch = getchar();
	result = ch-'0';
	while (true) {
		ch = getchar();
		if (ch < '0' || ch > '9') break;
		result = result*10 + (ch - '0');
	}
	return result;
}

template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

void usaco(string s){
  freopen((s+".in").c_str(), "r", stdin);
  freopen((s+".out").c_str(), "w", stdout);
}

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);
#ifdef LOCAL_DEFINE
	freopen("input.txt", "r", stdin);
#endif
  const int N = 1e6 + 5;
  int n, dp[ N ][ 3 ];
  char s[ N ], t[ N ];
  cin >> n >> (s + 1) >> (t + 1);
  memset( dp, 0x3f, sizeof dp );
  dp[ 0 ][ 0 ] = 0;
  for ( int i = 1 ; i <= n ; i++ ) {
    s[ i ] -= '0';
    t[ i ] -= '0';
    for ( int j = 0; j < 3; j++ ) {
      for( int k = 0; k < 3; k++ ) {
        int x = k ? k - 1 : s[ i ] , y = j ? j - 1 : s[ i - 1 ];
        dp[ i ][ k ] = min ( dp[ i ][ k ] , dp[ i - 1 ][ j ] + ( k and k != j ) + ( y == t[ i - 1 ] and x != t[ i ] ));
      }
    }
  }
  cout << min ( dp[ n ][ 0 ], min( dp[ n ][ 1 ], dp[ n ][ 2 ] ));
}

Compilation message (stderr)

lamp.cpp: In function 'void usaco(std::string)':
lamp.cpp:30:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   30 |   freopen((s+".in").c_str(), "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lamp.cpp:31:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   31 |   freopen((s+".out").c_str(), "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...