# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
219291 |
2020-04-05T05:15:20 Z |
rama_pang |
Lamps (JOI19_lamps) |
C++14 |
|
1000 ms |
65100 KB |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e7;
int N;
string A, B;
void Read() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> N >> A >> B;
}
int NaiveDP() {
vector<array<array<int, 4>, 4>> dp(N + 1); // dp[pos][second_last_operation][last_operation]
// dp[pos] means A[pos...N] = B[pos...N]
// operation 0 = skip operation
// operation 1 = off operation
// operation 2 = on operation
// operation 3 = xor operation
for (int pos = N - 1; pos >= 0; pos--) {
for (int second_last = 0; second_last < 4; second_last++) {
for (int last = 0; last < 4; last++) {
int &res = dp[pos][second_last][last];
// operation skip (0)
if (A[pos] == B[pos]) {
res = dp[pos + 1][last][0];
} else {
res = INF;
}
// operation off (1)
for (int nxt = pos; nxt < N; nxt++) {
if (B[nxt] != '0') break;
res = min(res, 1 + dp[nxt + 1][last][1]);
res = min(res, 1 - (second_last == 1 && last != 0 && last != 3) + dp[nxt + 1][0][1]);
}
// operation on (2)
for (int nxt = pos; nxt < N; nxt++) {
if (B[nxt] != '1') break;
res = min(res, 1 + dp[nxt + 1][last][2]);
res = min(res, 1 - (second_last == 2 && last != 0 && last != 3) + dp[nxt + 1][0][2]);
}
// operation xor (3)
for (int nxt = pos; nxt < N; nxt++) {
if (A[nxt] == B[nxt]) break;
res = min(res, 1 - (second_last == 1 && last == 2) + dp[nxt + 1][last][3]);
res = min(res, 1 - (second_last == 2 && last == 1) + dp[nxt + 1][last][3]);
}
}
}
}
return dp[0][0][0];
}
int main() {
Read();
cout << NaiveDP() << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
256 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
256 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Execution timed out |
1100 ms |
65100 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
256 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |