이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define all(x) (x).begin(),(x).end()
#define X first
#define Y second
#define sep ' '
#define endl '\n'
#define SZ(x) ll(x.size())
const ll MAXN = 1e6 + 10;
const ll LOG = 22;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; //998244353; //1e9 + 9;
int n , dp[MAXN][3];
string s , t;
int valid(int i , int j){
if(i < 0) return 1;
if(j == 0) return (s[i] == t[i]);
if(j == 1) return (t[i] == '0');
if(j == 2) return (t[i] == '1');
}
int main() {
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin >> n >> s >> t;
s = "." + s; t = "." + t;
dp[0][1] = dp[0][2] = MOD;
for(int i = 1 ; i <= n ; i++){
for(int j = 0 ; j < 3 ; j++){
dp[i][j] = MOD;
for(int k = 0 ; k < 3 ; k++){
dp[i][j] = min(dp[i][j] , dp[i - 1][k] + (j != k) + (valid(i , j) != valid(i - 1 , k)));
}
// cout << dp[i][j] << sep;
}
// cout << endl;
}
int ans = MOD;
for(int i = 0 ; i < 3 ; i++){
ans = min(ans , dp[n][i] + (i != 0) + 1 - valid(n , i));
}
cout << (ans + 1) / 2 << endl;
return 0;
}
/*
*/
컴파일 시 표준 에러 (stderr) 메시지
lamp.cpp: In function 'int valid(int, int)':
lamp.cpp:28:1: warning: control reaches end of non-void function [-Wreturn-type]
28 | }
| ^
# | 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... |