# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
124533 |
2019-07-03T13:31:14 Z |
vex |
Lamps (JOI19_lamps) |
C++14 |
|
30 ms |
20108 KB |
#include <bits/stdc++.h>
#define maxn 1000005
#define INF 10020000
using namespace std;
int n;
string a,b;
int dp[maxn][2][2];
int minn(int x)
{
return min(min(dp[x][0][0],dp[x][0][1]), min(dp[x][1][0],dp[x][1][1]));
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin>>n;
cin>>a;
cin>>b;
if(a[0]==b[0])
{
dp[0][0][0]=0;
dp[0][0][1]=INF;
dp[0][1][0]=1;
dp[0][1][1]=2;
}
else
{
dp[0][0][0]=INF;
dp[0][0][1]=1;
dp[0][1][0]=1;
dp[0][1][1]=2;
}
for(int i=1;i<n;i++)
{
if(a[i]==b[i])
{
dp[i][0][0]=minn(i-1);
dp[i][0][1]=INF;
dp[i][1][0]=minn(i-1)+1;
if(b[i-1]==b[i])dp[i][1][0]=min(dp[i][1][0],dp[i-1][1][0]);
else dp[i][1][0]=min(dp[i][1][0],dp[i-1][1][1]);
dp[i][1][1]=minn(i-1)+2;
if(b[i]==b[i-1])dp[i][1][1]=min(dp[i][1][1],dp[i-1][1][1]);
if(b[i-1]+b[i]==1)dp[i][1][1]=min(dp[i][1][1],dp[i-1][1][0]+1);
dp[i][1][1]=min( min(dp[i-1][0][1],dp[i-1][1][1])+1, dp[i][1][1]);
}
else
{
dp[i][0][0]=INF;
dp[i][0][1]=min( min(dp[i-1][0][1],dp[i-1][1][1]), min(dp[i-1][0][0],dp[i-1][1][0])+1 );
dp[i][1][0]=minn(i-1)+1;
if(b[i-1]==b[i])dp[i][1][0]=min(dp[i][1][0],dp[i-1][1][0]);
else dp[i][1][0]=min(dp[i][1][0],dp[i-1][1][1]);
dp[i][1][1]=minn(i-1)+2;
if(b[i]==b[i-1])dp[i][1][1]=min(dp[i][1][1],dp[i-1][1][1]);
if(b[i-1]+b[i]==1)dp[i][1][1]=min(dp[i][1][1],dp[i-1][1][0]+1);
dp[i][1][1]=min( min(dp[i-1][0][1],dp[i-1][1][1])+1, dp[i][1][1]);
}
}
/*for(int i=0;i<n;i++)
{
cout<<i<<": "<<dp[i][0][0]<<" "<<dp[i][0][1]<<" "<<dp[i][1][0]<<" "<<dp[i][1][1]<<endl;
}*/
cout<<minn(n-1)<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
248 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
504 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
392 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
248 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
504 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
392 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
24 ms |
20044 KB |
Output is correct |
8 |
Correct |
30 ms |
20044 KB |
Output is correct |
9 |
Correct |
28 ms |
20084 KB |
Output is correct |
10 |
Correct |
27 ms |
20108 KB |
Output is correct |
11 |
Correct |
27 ms |
20040 KB |
Output is correct |
12 |
Correct |
27 ms |
20036 KB |
Output is correct |
13 |
Correct |
27 ms |
20048 KB |
Output is correct |
14 |
Correct |
28 ms |
20040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
248 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
504 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
392 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |