# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1013844 | 2024-07-04T06:50:48 Z | toan2602 | Lamps (JOI19_lamps) | C++14 | 14 ms | 19976 KB |
#include<bits/stdc++.h> using namespace std; int n, dp[1000005], p0[1000005], p1[1000005], dif[1000005]; string a, b; void solve() { cin >> n >> a >> b; a = ' ' + a; b = ' ' + b; a[0] = '#'; b[0] = '&'; int cnt =0, res = 0; for (int i = 1; i < b.size(); i++) { if(b[i] == '0') p0[i] = (b[i-1] == '0' ? p0[i-1] + 1 : 1); else p1[i] = (b[i-1] == '1' ? p1[i-1] + 1 : 1); if(a[i] != b[i]) dif[i] = (a[i-1] != b[i-1] ? dif[i-1] : i-1); } for (int i = 1; i < a.size(); i++) { if(a[i] == b[i]) dp[i] = dp[i-1]; else dp[i] = min(dp[dif[i]] + 1, dp[i-1]+1); if(b[i] == '0') dp[i] = min(dp[i-p0[i]] + 1, dp[i]); else dp[i] = min(dp[i-p1[i]]+1, dp[i]); } cout << dp[n]; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; // cin >> t; while(t--) { solve(); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 464 KB | Output is correct |
4 | Correct | 0 ms | 464 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 0 ms | 460 KB | Output is correct |
10 | Correct | 0 ms | 344 KB | Output is correct |
11 | Correct | 0 ms | 348 KB | Output is correct |
12 | Correct | 1 ms | 348 KB | Output is correct |
13 | Incorrect | 0 ms | 348 KB | Output isn't correct |
14 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 464 KB | Output is correct |
4 | Correct | 0 ms | 464 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 0 ms | 460 KB | Output is correct |
10 | Correct | 0 ms | 344 KB | Output is correct |
11 | Correct | 0 ms | 348 KB | Output is correct |
12 | Correct | 1 ms | 348 KB | Output is correct |
13 | Incorrect | 0 ms | 348 KB | Output isn't correct |
14 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 464 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 464 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 10 ms | 11984 KB | Output is correct |
8 | Correct | 13 ms | 19904 KB | Output is correct |
9 | Correct | 13 ms | 19780 KB | Output is correct |
10 | Correct | 14 ms | 19960 KB | Output is correct |
11 | Correct | 12 ms | 19976 KB | Output is correct |
12 | Correct | 12 ms | 15872 KB | Output is correct |
13 | Correct | 11 ms | 15364 KB | Output is correct |
14 | Correct | 14 ms | 19968 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 464 KB | Output is correct |
4 | Correct | 0 ms | 464 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 0 ms | 460 KB | Output is correct |
10 | Correct | 0 ms | 344 KB | Output is correct |
11 | Correct | 0 ms | 348 KB | Output is correct |
12 | Correct | 1 ms | 348 KB | Output is correct |
13 | Incorrect | 0 ms | 348 KB | Output isn't correct |
14 | Halted | 0 ms | 0 KB | - |