# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
796652 | 2023-07-28T15:21:10 Z | vjudge1 | Lamps (JOI19_lamps) | C++17 | 1 ms | 212 KB |
// Author : حسن #include <bits/stdc++.h> using namespace std; #define TL ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); #define rall(s) s.rbegin(),s.rend() #define all(s) s.begin(),s.end() #define pb push_back #define fi first #define se second #define ll long long #define ld long double #define YES cout<<"YES\n" #define Yes cout<<"Yes\n" #define yes cout<<"yes\n" #define NO cout<<"NO\n" #define No cout<<"No\n" #define no cout<<"no\n" const int N = 1e6 + 9 , mod = 1e9 + 7; ll c[N] = {} , dp[N] = {} , a[N] = {}, b[N] = {} , d[N][3][2]; void solve(){ ll q , i , j , m , n , z , s = 0, f, l , r , k , x , y , mn = 1e18 , mx = 0; cin>>n; string a , b; cin>>a>>b; for(i = 0;i <= n; i++) for(j = 0; j < 3; j++) for(k = 0; k < 2; k++) d[i][j][k] = 1e9; d[0][0][0] = 0; for(i = 1; i <= n; i++){ for(x = 0; x < 3; x++){ for(y = 0; y < 2; y++){ d[i][x][y] = min(d[i][x][y] , d[i - 1][x][y]); d[i][0][y] = min(d[i][0][y] , d[i - 1][x][y]); d[i][x][0] = min(d[i][x][0] , d[i - 1][x][y]); d[i][0][0] = min(d[i][0][0] , d[i - 1][x][y]); if(x == 0){ d[i][1][y] = min(d[i][1][y] , d[i - 1][x][y] + 1); d[i][2][y] = min(d[i][2][y] , d[i - 1][x][y] + 1); } if(x == 0 && y == 0){ d[i][1][1] = min(d[i][1][1] , d[i - 1][x][y] + 2); d[i][2][1] = min(d[i][2][1] , d[i - 1][x][y] + 2); } if(y == 0){ d[i][x][1] = min(d[i][x][1] , d[i - 1][x][y] + 1); } } } for(x = 0;x < 3; x++){ for(y = 0;y < 2; y++){ l = a[i] - '0'; r = b[i] - '0'; if(x == 1) l = 1; if(x == 2) l = 0; if(y == 1) l = 1 - l; if(l != r) d[i][x][y]= 1e9; } } } for(i = 0;i < 3; i++) for(j = 0; j < 2; j++) mn = min(mn , d[n][i][j]); cout<<mn; } int main(){ /* TL; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif*/ int t = 1; //cin>>t; while(t--) { solve(); } } // Author : حسن
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Incorrect | 1 ms | 212 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |