Submission #245759

#TimeUsernameProblemLanguageResultExecution timeMemory
245759pavelLamps (JOI19_lamps)C++14
0 / 100
19 ms8064 KiB
#include <cstdio>
#include <algorithm>


using namespace std;

const int MAXN = 1000000;

int n;
char a[MAXN], b[MAXN];
int chg[MAXN];

int main(){
    scanf("%d", &n);
    scanf("%s", a);
    scanf("%s", b);
    for(int i=1;i<n;++i){
        chg[i] = chg[i-1];
        if(b[i] != b[i-1]) chg[i]++;
    }

    int l = 0, r = n;
    int sol = MAXN;
    int flips = 0;
    while(l != r){
        if(flips%2 == 0){
            while(a[l]==b[l] && l<r) l++;
            while(a[r-1]==b[r-1] && l<r) r--;
        }else{
            while(a[l]!=b[l] && l<r) l++;
            while(a[r-1]!=b[r-1] && l<r) r--;
        }
        if(l == r){
            sol = min(sol, flips);
            break;
        }
        int cost = (chg[r-1] - chg[l] + 1) / 2;
        sol = min(sol, flips+1+cost);
        flips++;
    }
    printf("%d\n", sol);
}

Compilation message (stderr)

lamp.cpp: In function 'int main()':
lamp.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
lamp.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%s", a);
     ~~~~~^~~~~~~~~
lamp.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     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...