답안 #245780

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
245780 2020-07-07T11:37:37 Z pavel Lamps (JOI19_lamps) C++14
4 / 100
21 ms 7296 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 = n;
    int flips = 0;
    while(l != r){
        if(flips%2 == 0){
            while(l<r && a[l]==b[l]) l++;
            while(l<r && a[r-1]==b[r-1]) r--;
        }else{
            while(l<r && a[l]!=b[l]) l++;
            while(l<r && a[r-1]!=b[r-1]) 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 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 384 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 256 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 4 ms 256 KB Output is correct
12 Correct 4 ms 256 KB Output is correct
13 Incorrect 5 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 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 384 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 256 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 4 ms 256 KB Output is correct
12 Correct 4 ms 256 KB Output is correct
13 Incorrect 5 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 256 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 17 ms 7296 KB Output is correct
8 Correct 20 ms 6912 KB Output is correct
9 Correct 20 ms 6912 KB Output is correct
10 Correct 21 ms 6912 KB Output is correct
11 Correct 21 ms 6912 KB Output is correct
12 Correct 17 ms 6912 KB Output is correct
13 Correct 19 ms 6912 KB Output is correct
14 Correct 19 ms 6904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 4 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 384 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 256 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 4 ms 256 KB Output is correct
12 Correct 4 ms 256 KB Output is correct
13 Incorrect 5 ms 256 KB Output isn't correct
14 Halted 0 ms 0 KB -