# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
245780 | pavel | Lamps (JOI19_lamps) | C++14 | 21 ms | 7296 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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);
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |