Submission #236618

# Submission time Handle Problem Language Result Execution time Memory
236618 2020-06-02T15:28:27 Z muhammad_hokimiyon Lamps (JOI19_lamps) C++14
4 / 100
307 ms 27900 KB
#include <bits/stdc++.h>

//#pragma GCC optimize("Ofast")

#define fi first
#define se second
#define ll long long
#define dl double long

using namespace std;

const int NN = 4e3 + 7;
const int N = 1e6 + 7;
const int M = 22;
const int mod = 1e9 + 7;
const ll inf = 1e18 + 7;
const dl rf = 1e-14;
const int B = sqrt(N);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n;
int p1[N];
int p2[N];
int p3[N];
char a[N];
char b[N];
int d[N][3];

void solve1()
{
    cin >> n;
    for( int i = 1; i <= n; i++ ){
        cin >> a[i];
    }
    for( int i = 1; i <= n; i++ ){
        cin >> b[i];
    }
    for( int i = 1; i < N; i++ ){
        for( int j = 0; j < 3; j++ ){
            d[i][j] = 1e9;
        }
    }
    for( int i = 1; i <= n; i++ ){
        p1[i] = p1[i - 1] + (b[i] == '0');
        p2[i] = p2[i - 1] + (b[i] == '1');
        p3[i] = p3[i - 1] + (b[i] == a[i]);
    }
    for( int i = 1; i <= n; i++ ){
        if( a[i] == b[i] ){
            for( int j = 0; j < 3; j++ ){
                for( int h = 0; h < 3; h++ ){
                    d[i][j] = min( d[i][j] , d[i - 1][h] );
                }
                //cout << i << " " << j << " " << d[i][j] << "\n";
            }
        }else{
            int l = 1 , r = i + 1;
            while( l < r ){
                int m = (l + r) / 2;
                if( p1[i] - p1[m - 1] == i - m + 1 )r = m;
                else l = m + 1;
            }
            vector < int > v;
            v.push_back(l);
            l = 1 , r = i + 1;
            while( l < r ){
                int m = (l + r) / 2;
                if( p2[i] - p2[m - 1] == i - m + 1 )r = m;
                else l = m + 1;
            }
            v.push_back(l);
            l = 1 , r = i + 1;
            while( l < r ){
                int m = (l + r) / 2;
                if( p3[i] - p3[m - 1] > 0 )l = m + 1;
                else r = m;
            }
            v.push_back(l);
            for( int j = 0; j < 3; j++ ){
                if( v[j] == i + 1 )v[j] += 2;
                for( int h = 0; h < 3; h++ ){
                    d[i][j] = min( d[i][j] , d[v[j] - 1][h] + 1 );
                }
                //cout << i << " " << j << " " << v[j] << " " << d[i][j] << "\n";
            }
        }
    }
    cout << min({ d[n][0] , d[n][1] , d[n][2] });
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    //freopen( "input.txt" , "r" , stdin );
    //freopen( "output.txt" , "w" , stdout );

    int cghf = 1;//cin >> cghf;
    while( cghf-- ){
        solve1();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 11 ms 12160 KB Output is correct
2 Correct 12 ms 12160 KB Output is correct
3 Correct 11 ms 12160 KB Output is correct
4 Correct 11 ms 12160 KB Output is correct
5 Correct 12 ms 12160 KB Output is correct
6 Correct 11 ms 12160 KB Output is correct
7 Correct 11 ms 12160 KB Output is correct
8 Correct 11 ms 12160 KB Output is correct
9 Correct 11 ms 12160 KB Output is correct
10 Correct 11 ms 12160 KB Output is correct
11 Correct 11 ms 12160 KB Output is correct
12 Correct 11 ms 12160 KB Output is correct
13 Incorrect 11 ms 12160 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 12160 KB Output is correct
2 Correct 12 ms 12160 KB Output is correct
3 Correct 11 ms 12160 KB Output is correct
4 Correct 11 ms 12160 KB Output is correct
5 Correct 12 ms 12160 KB Output is correct
6 Correct 11 ms 12160 KB Output is correct
7 Correct 11 ms 12160 KB Output is correct
8 Correct 11 ms 12160 KB Output is correct
9 Correct 11 ms 12160 KB Output is correct
10 Correct 11 ms 12160 KB Output is correct
11 Correct 11 ms 12160 KB Output is correct
12 Correct 11 ms 12160 KB Output is correct
13 Incorrect 11 ms 12160 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 12160 KB Output is correct
2 Correct 11 ms 12160 KB Output is correct
3 Correct 11 ms 12160 KB Output is correct
4 Correct 11 ms 12160 KB Output is correct
5 Correct 11 ms 12160 KB Output is correct
6 Correct 11 ms 12160 KB Output is correct
7 Correct 52 ms 27768 KB Output is correct
8 Correct 211 ms 27784 KB Output is correct
9 Correct 205 ms 27768 KB Output is correct
10 Correct 207 ms 27888 KB Output is correct
11 Correct 209 ms 27896 KB Output is correct
12 Correct 307 ms 27768 KB Output is correct
13 Correct 245 ms 27788 KB Output is correct
14 Correct 234 ms 27900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 12160 KB Output is correct
2 Correct 12 ms 12160 KB Output is correct
3 Correct 11 ms 12160 KB Output is correct
4 Correct 11 ms 12160 KB Output is correct
5 Correct 12 ms 12160 KB Output is correct
6 Correct 11 ms 12160 KB Output is correct
7 Correct 11 ms 12160 KB Output is correct
8 Correct 11 ms 12160 KB Output is correct
9 Correct 11 ms 12160 KB Output is correct
10 Correct 11 ms 12160 KB Output is correct
11 Correct 11 ms 12160 KB Output is correct
12 Correct 11 ms 12160 KB Output is correct
13 Incorrect 11 ms 12160 KB Output isn't correct
14 Halted 0 ms 0 KB -