Submission #245762

# Submission time Handle Problem Language Result Execution time Memory
245762 2020-07-07T10:56:26 Z pavel Lamps (JOI19_lamps) C++14
4 / 100
26 ms 8064 KB
#include <cstdio>
#include <algorithm>


using namespace std;

const int MAXN = 1000006;

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

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 time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 4 ms 256 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Incorrect 5 ms 256 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 4 ms 256 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Incorrect 5 ms 256 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 18 ms 6784 KB Output is correct
8 Correct 20 ms 8064 KB Output is correct
9 Correct 21 ms 8064 KB Output is correct
10 Correct 21 ms 8064 KB Output is correct
11 Correct 21 ms 8064 KB Output is correct
12 Correct 18 ms 8064 KB Output is correct
13 Correct 26 ms 8064 KB Output is correct
14 Correct 19 ms 8064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 4 ms 256 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Incorrect 5 ms 256 KB Output isn't correct
14 Halted 0 ms 0 KB -