답안 #245759

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
245759 2020-07-07T10:55:24 Z pavel Lamps (JOI19_lamps) C++14
0 / 100
19 ms 8064 KB
#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

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);
     ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 256 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 4 ms 256 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Incorrect 4 ms 256 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 256 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 4 ms 256 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Incorrect 4 ms 256 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 512 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Incorrect 19 ms 8064 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 256 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 4 ms 256 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Incorrect 4 ms 256 KB Output isn't correct
14 Halted 0 ms 0 KB -