제출 #173127

#제출 시각아이디문제언어결과실행 시간메모리
173127dennisstarLamps (JOI19_lamps)C++11
100 / 100
34 ms16084 KiB
#include <bits/stdc++.h>
#define fi first
#define se second
#define ryan bear
#define all(V) ((V).begin()), ((V).end())
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef vector<int> vim;
typedef vector<ll> vlm;

int N, D[3][1000010];
char A[1000010], B[1000010];

int main() {
	scanf("%d %s %s", &N, A+1, B+1);
    D[0][1] = (B[1] == '0') + 1; //changed to 0
    D[1][1] = (B[1] == '1') + 1; //changed to 1
    D[2][1] = (A[1] != B[1]);    //reversed
    for (int i=2; i<=N; i++) {
        D[0][i] = min(D[0][i-1] + (B[i]=='0'&&B[i-1]=='1'), D[2][i-1] + 1 + ((B[i]=='0')&&A[i-1]==B[i-1]));
        D[1][i] = min(D[1][i-1] + (B[i]=='1'&&B[i-1]=='0'), D[2][i-1] + 1 + ((B[i]=='1')&&A[i-1]==B[i-1]));
        D[2][i] = min({
            D[0][i-1] + (A[i]!=B[i]&&B[i-1]=='1'), 
            D[1][i-1] + (A[i]!=B[i]&&B[i-1]=='0'), 
            D[2][i-1] + (A[i]!=B[i]&&B[i-1]==A[i-1])
        });
    }
	printf("%d\n", min({D[0][N], D[1][N], D[2][N]}));
}

컴파일 시 표준 에러 (stderr) 메시지

lamp.cpp: In function 'int main()':
lamp.cpp:18:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %s %s", &N, A+1, B+1);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...