# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
235247 |
2020-05-27T13:58:51 Z |
Nodir_Bobiev |
Lamps (JOI19_lamps) |
C++17 |
|
1000 ms |
92284 KB |
/*
+----------------------------------------------------------------+
| In the name of Allah, the most Gracious and the most Merciful. |
+----------------------------------------------------------------+
Our hearts quake with fear of you
Our hearts wake with love for you
And to Islam we must be true
In everything we think and do.
--------------------------------
When your heart is breaking
And your pain makes you fall
Remember just remember
Allah Sees it all.
*/
# include <bits/stdc++.h>
# define FILE
using namespace std;
const int N = 1e6 + 100;
const int inf = 9;
string A,B;
int n;
vector < vector < int > > dp[N];
vector < vector < int > > oper= { {}, {1}, {2}, {3}, {1,1},
{1,2}, {1,3}, {2,1}, {2,2},
{2,3}, {3,1}, {3,2}, {3,3},
{1,2,3}, {1,3,2}, {2,1,3},
{2,3,1}, {3,1,2}, {3,2,1}
};
char op(int x, char c){
if( x == 0 ) return c;
if( x == 1 ) return '0';
if( x == 2 ) return '1';
if( c == '1' ) return '0';
return '1';
}
int get( vector < int >&v1, vector < int >&v2, int i=0, int j=0 ){
if( i == (int)v1.size() || j == (int)v2.size()-1)return 0;
int mx = 0;
if( v1[i] == v2[j] ) mx = get(v1, v2, i+1, j+1) + 1;
mx = max({mx, get(v1, v2, i+1, j), get(v1, v2, i, j+1)});
return mx;
}
int main(){
# ifdef FILEs
freopen( "input.txt", "r", stdin );
freopen( "output.txt", "w", stdout );
# endif
ios_base::sync_with_stdio(false);
cin >> n >> A >> B;
A = '0' + A;
B = '0' + B;
dp[0].push_back({0});
for( int i = 1; i <= n; i ++ ){
for( auto &v1: oper ){
for( auto c: v1 )
A[i] = op(c, A[i]);
if( A[i] != B[i] )
continue;
int res = inf;
for( auto v2: dp[i-1] ){
res = min( res, v2.back() + (int)v1.size() - get(v1, v2) );
}
if( res != inf ){
v1.push_back(res);
dp[i].push_back(v1);
v1.pop_back();
}
}
}
int ans = inf;
for( auto vc: dp[n] )ans = min( ans, vc.back() );
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
23808 KB |
Output is correct |
2 |
Correct |
18 ms |
23680 KB |
Output is correct |
3 |
Incorrect |
18 ms |
23808 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
23808 KB |
Output is correct |
2 |
Correct |
18 ms |
23680 KB |
Output is correct |
3 |
Incorrect |
18 ms |
23808 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
23808 KB |
Output is correct |
2 |
Correct |
23 ms |
23808 KB |
Output is correct |
3 |
Correct |
21 ms |
23808 KB |
Output is correct |
4 |
Correct |
18 ms |
23808 KB |
Output is correct |
5 |
Correct |
18 ms |
23808 KB |
Output is correct |
6 |
Correct |
18 ms |
23808 KB |
Output is correct |
7 |
Execution timed out |
1095 ms |
92284 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
23808 KB |
Output is correct |
2 |
Correct |
18 ms |
23680 KB |
Output is correct |
3 |
Incorrect |
18 ms |
23808 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |