답안 #105166

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
105166 2019-04-10T19:38:44 Z reality Lamps (JOI19_lamps) C++17
4 / 100
83 ms 19960 KB
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define vii vector < pii >
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
template < class P , class Q > ostream& operator<<(ostream& stream, pair < P , Q > v){ stream << "(" << v.fi << ',' << v.se << ")"; return stream;}
template < class T > ostream& operator<<(ostream& stream, const vector<T> v){ stream << "[ "; for (int i=0; i<(int)v.size(); i++) stream << v[i] << " "; stream << "]"; return stream;}
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
const int N = 1e6 + 5;
const int oo = 1e9;
char A[N];
char B[N];
int dp[N][2];
int d1[N],d2[N];
int main(void) {
    int n;
    cin>>n;
    cin>>(A+1)>>(B+1);
    dp[0][0] = 0;
    dp[0][1] = 1;
    for (int i = 1;i <= n;++i)
    	dp[i][0] = dp[i][1] = oo;
    for (int i = 1;i <= n;++i) {
    	d1[i] = B[i] == '1' ? d1[i - 1] : i;
    	d2[i] = B[i] == '0' ? d2[i - 1] : i;
    }
    for (int i = 1;i <= n;++i) {
    	smin(dp[i][0],min(dp[i - 1][0],dp[i - 1][1]) + (A[i] != B[i]));
    	smin(dp[i][1],min(dp[i - 1][0] + 1,dp[i - 1][1]) + (A[i] == B[i]));
    	int Ind = B[i] == '1' ? d1[i] - 1 : d2[i] - 1;
 		smin(dp[i][0],min(dp[Ind][0],dp[Ind][1]) + 1);
    	smin(dp[i][1],min(dp[Ind][0],dp[Ind][1]) + 2);
    	
    }
    cout << min(dp[n][0],dp[n][1]) << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Incorrect 2 ms 384 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Incorrect 2 ms 384 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 356 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 77 ms 19832 KB Output is correct
8 Correct 76 ms 19832 KB Output is correct
9 Correct 71 ms 19832 KB Output is correct
10 Correct 72 ms 19960 KB Output is correct
11 Correct 72 ms 19832 KB Output is correct
12 Correct 76 ms 19832 KB Output is correct
13 Correct 79 ms 19832 KB Output is correct
14 Correct 83 ms 19832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Incorrect 2 ms 384 KB Output isn't correct
14 Halted 0 ms 0 KB -