제출 #252997

#제출 시각아이디문제언어결과실행 시간메모리
252997hollwo_pelwLamps (JOI19_lamps)C++17
100 / 100
79 ms67144 KiB
/*
 /+==================================================+\
//+--------------------------------------------------+\\
|.|\\...>>>>>>> Hollwo_Pelw(ass) 's code <<<<<<<...//|.|
\\+--------------------------------------------------+//
 \+==================================================+/
*/
#include <bits/stdc++.h>
using namespace std;
// type
typedef long long ll;
typedef long double ld;
// loop
//#define For(i, l, r)        for (int i = l; i < r; i++)
//#define ForE(i, l, r)       for (int i = l; i <= r; i++)
//#define Ford(i, r, l)       for (int i = r; i > l; i--)
//#define FordE(i, r, l)      for (int i = r; i >= l; i--)
//#define Fora(i, a)          for (auto i : a)
// I/O
#define open(file, in, out) if (fopen(file in, "r")) {        \
                                freopen(file in, "r", stdin);  \
                                freopen(file out, "w", stdout); \
                            }
#define FAST_IO             std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define setpre(n)           fixed << setprecision(n)
// pair
#define F                   first
#define S                   second
#define pii                 pair<int, int>
#define pll                 pair<ll, ll>
#define pdd                 pair<ld, ld>
// vector & !!?(string)
#define eb                  emplace_back
#define pb                  push_back
#define all(a)              a.begin(), a.end()
#define rall(a)             a.rbegin(), a.rend()
#define sz(a)               a.size()
#define len(a)              a.length()
// geometry calculate
#define pi                  acos(-1.0)
#define g_sin(a)            sin(a*pi/180)
#define g_cos(a)            cos(a*pi/180)
#define g_tan(a)            tan(a*pi/180)
// set val
#define ms0(a)              memset(a,        0, sizeof(a));
#define ms1(a)              memset(a,        1, sizeof(a));
#define msn1(a)             memset(a,       -1, sizeof(a));
#define msinf(a)            memset(a, 0x3f3f3f, sizeof(a));
// constant
const int mod1 = 998244353, mod = 1e9+7;
const int MAXN = 100005, MAXM = 200010;
// code
#define int long long

int dp[(int) 1e6 + 6][8];
int tr[8][8];
void Solve() {
    string a, b; int n;
    cin >> n >> a >> b;
    for (int i = 0; i < 8; i++){
        for (int j = 0; j < 8; j++){
            int t = (i | j) ^ i;
            while (t){
                tr[i][j] += t % 2;
                t /= 2;
            }
        }
    }

    for (int i = 0; i <= n; i++){
        for (int j = 0; j < 8; j++){
            dp[i][j] = 1e9;
        }
    }
    dp[0][0] = 0;
    for (int i = 1; i <= n; i++){
        if (a[i-1] == '1' & b[i-1] == '1'){
            for (int j = 0; j < 8; j++){
                dp[i][0] = min(dp[i][0], dp[i-1][j] + tr[j][0]);
                dp[i][2] = min(dp[i][2], dp[i-1][j] + tr[j][2]);
                dp[i][5] = min(dp[i][5], dp[i-1][j] + tr[j][5]);
            }
        }if (a[i-1] == '1' & b[i-1] == '0'){
            for (int j = 0; j < 8; j++){
                dp[i][1] = min(dp[i][1], dp[i-1][j] + tr[j][1]);
                dp[i][4] = min(dp[i][4], dp[i-1][j] + tr[j][4]);
                dp[i][6] = min(dp[i][6], dp[i-1][j] + tr[j][6]);
            }
        }if (a[i-1] == '0' & b[i-1] == '0'){
            for (int j = 0; j < 8; j++){
                dp[i][0] = min(dp[i][0], dp[i-1][j] + tr[j][0]);
                dp[i][1] = min(dp[i][1], dp[i-1][j] + tr[j][1]);
                dp[i][6] = min(dp[i][6], dp[i-1][j] + tr[j][6]);
            }
        }if (a[i-1] == '0' & b[i-1] == '1'){
            for (int j = 0; j < 8; j++){
                dp[i][2] = min(dp[i][2], dp[i-1][j] + tr[j][2]);
                dp[i][4] = min(dp[i][4], dp[i-1][j] + tr[j][4]);
                dp[i][5] = min(dp[i][5], dp[i-1][j] + tr[j][5]);
            }
        }
    }
    int ans = 1e9;
    for (int i = 0; i < 8; i++){
        ans = min(ans, dp[n][i]);
    }
//    for (int j = 0; j < 8; j ++){
//        for (int i = 1; i <= n; i++){
//            if (dp[i][j] == 1e9) cout << "X ";
//            else cout << dp[i][j] << ' ';
//        }
//        cout << endl;
//    }
    cout << ans;
}

signed main(){
    open("", ".inp", ".out");
    FAST_IO; int TC = 1;
//    cin >> TC;
    while(TC--) Solve();
    return 0;
}
/*

./-=====>>><<<-------- DEBUG -------->>><<<=====-\.
/.................................................\

+====================== INP ======================+


+====================== OUT ======================+


\................................................./
.\-=====>>><<<--------= END =-------->>><<<=====-/.
*/

컴파일 시 표준 에러 (stderr) 메시지

lamp.cpp: In function 'void Solve()':
lamp.cpp:77:20: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
         if (a[i-1] == '1' & b[i-1] == '1'){
lamp.cpp:83:21: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
         }if (a[i-1] == '1' & b[i-1] == '0'){
lamp.cpp:89:21: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
         }if (a[i-1] == '0' & b[i-1] == '0'){
lamp.cpp:95:21: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
         }if (a[i-1] == '0' & b[i-1] == '1'){
lamp.cpp: In function 'int main()':
lamp.cpp:21:40: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
                                 freopen(file in, "r", stdin);  \
                                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
lamp.cpp:118:5: note: in expansion of macro 'open'
     open("", ".inp", ".out");
     ^~~~
lamp.cpp:22:40: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
                                 freopen(file out, "w", stdout); \
                                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
lamp.cpp:118:5: note: in expansion of macro 'open'
     open("", ".inp", ".out");
     ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...