답안 #897805

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
897805 2024-01-03T17:44:41 Z Mr_Husanboy Lamps (JOI19_lamps) C++17
0 / 100
1000 ms 8200 KB
#include<bits/stdc++.h>

using namespace std;
using ll = long long;

#define ff first
#define ss second
#define all(a) (a).begin(), (a).end()

template<typename T>
int len(T &a){
    return a.size();
}


void solve(){
    int n; cin >> n;
    string a, b; cin >> a >> b;
    for(int i = 0; i < n; i ++){
        a[i] = (a[i] == b[i] ? '0' : '1');
    }
    a = "$" + a;
    b = "$" + b;
    //cout << a << '\n' << b << '\n';
    vector<int> dp(n + 1);
    for(int i = 1; i <= n; i ++){
        if(a[i] == '0'){
            dp[i] = dp[i - 1];
            continue;
        }
        dp[i] = dp[i - 1] + 1;
        int one = b[i] == '1';
        int zer = b[i] == '0';
        int xr = 1;
        for(int j = i - 1; j > 0; j --){
            if(b[j] != b[j + 1]){
                if(b[j] == '0') zer ++;
                else one ++;
            }
            if(a[j] == '1' && a[j + 1] == '0'){
                xr ++;
            }

            dp[i] = min({dp[i], dp[j - 1] + xr, dp[j - 1] + one + 1, dp[j - 1] + zer + 1});
        }
    }
    cout << dp[n];
}  

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    int testcases = 1;

    #ifdef Tests
    cin >> testcases;
    #endif

    while(testcases --){
        solve();
        if(testcases) cout << '\n';
        #ifdef LOCAL
        else
        cout << '\n';
        cout << "________________________" << endl;
        #endif
    }
    #ifdef LOCAL
    cout << "done" << endl;
    #endif
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 452 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 452 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Incorrect 0 ms 348 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 452 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 452 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Incorrect 0 ms 348 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 456 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 8 ms 8200 KB Output is correct
8 Execution timed out 1067 ms 8196 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 452 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 452 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Incorrect 0 ms 348 KB Output isn't correct
14 Halted 0 ms 0 KB -