| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1311977 | nanaseyuzuki | Lamps (JOI19_lamps) | C++20 | 55 ms | 28032 KiB |
#include <bits/stdc++.h>
// Kazusa_Megumi
#define ll long long
#define fi first
#define se second
#define pii pair<int, int>
#define all(a) a.begin(), a.end()
using namespace std;
#ifdef LOCAL
#include "C:\Users\Dell\Downloads\template\template\icpc-notebook\Utilities\debug.h"
#else
#define debug(...) 42
#endif
const int mn = 1e6 + 5, mod = 1e9 + 7, inf = 2e9;
int n, dp[mn][6], val[6][6];
string a, b;
// dp[i][0] : keep
// dp[i][1] : toggle
// dp[i][2] : set 0
// dp[i][3] : set 1
// dp[i][4] : set 0 + toggle
// dp[i][5] : set 1 + toggle
void solve() {
cin >> n >> a >> b;
fill(&dp[0][0], &dp[0][0] + mn * 6, inf);
a = "#" + a, b = "#" + b;
for(int i = 0; i < 6; i++){
for(int j = 0; j < 6; j++){
if(j == 0 || i == j) val[i][j] = 0;
else if(j == 1) val[i][j] = (i >= 4 ? 0 : 1);
else if(j == 2) val[i][j] = (i == 4 ? 0 : 1);
else if(j == 3) val[i][j] = (i == 5 ? 0 : 1);
else if(j == 4) val[i][j] = ((i == 1 || i == 2) ? 1 : 2);
else if(j == 5) val[i][j] = ((i == 1 || i == 3) ? 1 : 2);
}
}
dp[0][0] = 0;
for(int i = 1; i <= n; i++){
int st = a[i] - '0';
for(int nxt = 0; nxt < 6; nxt ++){
int cur = st;
if(nxt > 1) cur = (nxt <= 3 ? nxt - 2 : 1 - (nxt - 4));
else if(nxt == 1) cur = 1 - cur;
if(cur != b[i] - '0') continue;
for(int pre = 0; pre < 6; pre ++){
dp[i][nxt] = min(dp[i][nxt], dp[i - 1][pre] + val[pre][nxt]);
}
}
}
int res = inf;
for(int i = 0; i < 6; i++) res = min(res, dp[n][i]);
cout << res << '\n';
}
main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
if (fopen("Kazuki.INP", "r")) {
freopen("Kazuki.INP", "r", stdin);
freopen("Kazuki.OUT", "w", stdout);
}
int t = 1;
// cin >> t;
while (t--) solve();
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... | ||||
