Submission #959405

#TimeUsernameProblemLanguageResultExecution timeMemory
959405thunoproLamps (JOI19_lamps)C++14
100 / 100
55 ms16392 KiB
#include <bits/stdc++.h>
#define Y8o "lamps"
#define maxn 1000005
#define ll long long
#define pii pair<int, int>
#define gb(i, j) ((i >> j) & 1)
 
using namespace std;
 
/// okay?
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll GetRandom(ll l, ll r)
{
    return uniform_int_distribution<ll> (l, r) (rng);
}
void iof()   /// ------------------inp_out file!-----------------///
{
    if(fopen(Y8o".inp", "r"))
    {
        freopen(Y8o".inp", "r", stdin);
        freopen(Y8o".out", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
void ctime()   /// ------------------check time!-----------------///
{
    cerr << "\n" << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}
/// okay!
 
int n;
string a, b;
int dp[maxn][3];
 
char make(int pos, int operation)
{
    if(operation < 2) return operation + '0';
    return a[pos];
}
 
void solve()
{
    cin >> n;
    cin >> a >> b;
    a = ' ' + a, b = ' ' + b;
 
    memset(dp, 0x3f, sizeof dp);
    dp[0][2] = 0;
 
    for(int i = 1; i <= n; i ++)
    {
        for(int j = 0; j <= 2; j ++)
        {
            for(int t = 0; t <= 2; t ++) /// dp[i - 1][j] --> dp[i][t]
            {
                int cost = dp[i - 1][j];
 
                if(j != t && t != 2)
                    cost ++;
                if( (i == 1 || make(i - 1, j) == b[i - 1]) && make(i, t) != b[i] )
                    cost ++;
 
                dp[i][t] = min(dp[i][t], cost);
            }
        }
    }
 
    cout << min({ dp[n][0], dp[n][1], dp[n][2] });
}
 
 
int main()
{
    iof();
 
    int nTest = 1;
//    cin >> nTest;
 
    while(nTest --)
    {
        solve();
    }
 
    ctime();
    return 0;
}

Compilation message (stderr)

lamp.cpp: In function 'void iof()':
lamp.cpp:20:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         freopen(Y8o".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
lamp.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         freopen(Y8o".out", "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...