# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
217297 |
2020-03-29T11:38:16 Z |
pit4h |
Lamps (JOI19_lamps) |
C++14 |
|
1000 ms |
254916 KB |
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+1;
int dp[N][4][4][4], min_dp[N];
int main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n;
string s, t;
cin>>n>>s>>t;
for(int i=0; i<=n; ++i) {
for(int a=0; a<=3; ++a) {
for(int b=0; b<=3; ++b) {
for(int c=0; c<=3; ++c) {
dp[i][a][b][c] = n;
}
}
}
}
dp[0][0][0][0]=0;
for(int i=1; i<=n; ++i) {
int v1 = n;
for(int a=0; a<=3; ++a) {
for(int b=0; b<=3; ++b) {
for(int c=0; c<=3; ++c) {
v1 = min(v1, dp[i-1][a][b][c]);
}
}
}
if(s[i-1]==t[i-1]) {
dp[i][0][0][0] = v1;
}
for(int a=1; a<=3; ++a) {
int v2 = n;
for(int j=0; j<=3; ++j) {
for(int k=0; k<=3; ++k) {
for(int l=0; l<=3; ++l) {
if(j==a || k==a || l==a) {
v2 = min(v2, dp[i-1][j][k][l]);
}
}
}
}
if((a==1 && t[i-1]=='0') || (a==2 && t[i-1]=='1') || (a==3 && s[i-1]!=t[i-1])) {
dp[i][a][0][0] = min(v1+1, v2);
}
for(int b=1; b<=3; ++b) {
if(b==a) continue;
int v3 = n;
for(int j=0; j<=3; ++j) {
for(int k=0; k<=3; ++k) {
for(int l=0; l<=3; ++l) {
if((j==a && k==b) || (k==a && l==b)) {
v3 = min(v3, dp[i-1][j][k][l]);
}
}
}
}
if((a==1 && t[i-1]=='0') || (a==2 && t[i-1]=='1') || (a==3 && ((b==1 && t[i-1]=='1') || (b==2 && t[i-1]=='0')))) {
dp[i][a][b][0] = min(v1+2, min(v2+1, v3));
}
else {
continue;
}
for(int c=1; c<=3; ++c) {
if(c==a || c==b) continue;
int v4 = dp[i-1][a][b][c];
dp[i][a][b][c] = min(v1+3, min(v2+2, min(v3+1, v4)));
}
}
}
}
int ans = n;
for(int a=0; a<=3; ++a) {
for(int b=0; b<=3; ++b) {
for(int c=0; c<=3; ++c) {
ans = min(ans, dp[n][a][b][c]);
}
}
}
cout<<ans;
}
# |
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 |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
5 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 |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
17 |
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 |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
5 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 |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Execution timed out |
1108 ms |
254916 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 |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
5 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 |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |