이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define a first
#define b second
#define pb push_back
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
int aa[n];
int bb[n];
char ss;
for(int i=0;i<n;i++){
cin>>ss;
if(ss=='1'){
aa[i]=1;
}
else{
aa[i]=0;
}
}
for(int i=0;i<n;i++){
cin>>ss;
if(ss=='1'){
bb[i]=1;
}
else{
bb[i]=0;
}
}
int dp[n][3];
if(aa[0]==bb[0]){
dp[0][2]=0;
}
else{
dp[0][2]=1;
}
if(bb[0]==1){
dp[0][0]=2;
}
else{
dp[0][0]=1;
}
if(bb[0]==0){
dp[0][1]=2;
}
else{
dp[0][1]=1;
}
for(int i=1;i<n;i++){
for(int j=0;j<3;j++){
dp[i][j]=n;
//0
int co=n;
int x,y,z;
x=dp[i-1][0];
y=dp[i-1][1]+1;
z=dp[i-1][2]+1;
if(bb[i-1]==0 and bb[i]==1){
x+=1;
}
if(bb[i-1]==1 and bb[i]==1){
y+=1;
}
if(bb[i-1]==aa[i-1] and bb[i]==1){
z+=1;
}
dp[i][0]=min(x,min(y,z));
//1
x=dp[i-1][0]+1;
y=dp[i-1][1];
z=dp[i-1][2]+1;
if(bb[i-1]==0 and bb[i]==0){
x+=1;
}
if(bb[i-1]==1 and bb[i]==0){
y+=1;
}
if(bb[i-1]==aa[i-1] and bb[i]==0){
z+=1;
}
dp[i][1]=min(x,min(y,z));
//2
x=dp[i-1][0];
y=dp[i-1][1];
z=dp[i-1][2];
if(bb[i-1]==0 and bb[i]==1-aa[i]){
x+=1;
}
if(bb[i-1]==1 and bb[i]==1-aa[i]){
y+=1;
}
if(bb[i-1]==aa[i-1] and bb[i]==1-aa[i]){
z+=1;
}
dp[i][2]=min(x,min(y,z));
}
}
cout<<min(dp[n-1][0],min(dp[n-1][1],dp[n-1][2]))<<endl;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
lamp.cpp: In function 'int main()':
lamp.cpp:57:8: warning: unused variable 'co' [-Wunused-variable]
int co=n;
^~| # | 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... |