| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1281408 | vuquangsang | Lamps (JOI19_lamps) | C++20 | 41 ms | 14144 KiB |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 2;
const int inf = 1e9 + 2;
int n; string a, b;
int dp[N][3];
void solve()
{
cin >> n >> a >> b;
a = ' ' + a;
b = ' ' + b;
dp[0][0] = dp[0][1] = inf;
dp[0][2] = 0;
for(int i = 1; i <= n; i++) {
bool tar = b[i] - '0';
for(int j : {0, 1, 2}) dp[i][j] = inf;
for(int j : {0, 1, 2}) if(dp[i - 1][j] != inf) {
bool tog = 0;
if(i > 1) {
int cur = (j == 2 ? a[i - 1] - '0' : j);
tog = (cur != (b[i - 1] - '0'));
}
for(int k : {0, 1, 2}) {
if(j != k && max(j, k) < 2) continue;
int cur = k;
if(cur == 2) cur = a[i] - '0';
dp[i][k] = min({dp[i][k], dp[i - 1][j] + (j == 2 && k < 2) + (!tog && cur != tar)});
}
}
}
cout << min({dp[n][0], dp[n][1], dp[n][2]});
}
main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define TASK "lamps"
if(fopen(TASK".INP", "r")) {
freopen(TASK".INP", "r", stdin);
freopen(TASK".OUT", "w", stdout);
}
solve();
cerr << "\nTime" << 0.001 * clock() << "s "; return 0;
}
컴파일 시 표준 에러 (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... | ||||
