# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1229888 | hainam2k9 | Lamps (JOI19_lamps) | C++20 | 18 ms | 6356 KiB |
#include <bits/stdc++.h>
#define tt cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0)
#define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define db long double
#define sz(a) ((int)(a).size())
#define pb emplace_back
#define pf emplace_front
#define pob pop_back
#define pof pop_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define ins emplace
#define mp make_pair
using namespace std;
const int MOD = 1e9+7, MAXN = 1e6+5;
const string NAME = "";
int n,dp[MAXN],prefon=0,prefoff=0;
char a[MAXN],b[MAXN];
int main()
{
tt;
if(fopen((NAME + ".INP").c_str(), "r")) fo;
cin >> n;
for(int i = 1; i<=n; ++i)
cin >> a[i];
for(int i = 1; i<=n; ++i)
cin >> b[i];
memset(dp,0x3f,sizeof(dp));
dp[0]=0;
for(int i=1, j=0, MINoff=0, MINon=0; i<=n; ++i){
if(b[i]=='0'&&b[i-1]!=b[i]) ++prefoff;
if(b[i]=='1'&&b[i-1]!=b[i]) ++prefon;
if(a[i]==b[i]) j=i, dp[i]=dp[i-1];
else{
dp[i]=dp[j]+1;
if(b[i]=='0') dp[i]=min(dp[i],prefon+MINon+1);
else dp[i]=min(dp[i],prefoff+MINoff+1);
}
if(b[i]=='0') MINoff=min(MINoff,dp[i]-prefoff+(a[i]=='0'&&a[i]+1=='0'));
else MINon=min(MINon,dp[i]-prefon+(a[i]=='1'&&a[i+1]=='1'));
}
cout << dp[n];
}
컴파일 시 표준 에러 (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... |