답안 #1003818

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1003818 2024-06-20T18:21:53 Z Hanksburger Lamps (JOI19_lamps) C++17
4 / 100
22 ms 32164 KB
#include <bits/stdc++.h>
using namespace std;
int dp[1000005], dp1[1000005], dp2[1000005], mindp1[1000005], mindp2[1000005], ind[1000005];
vector<int> vec;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, sz=0, state=0;
    cin >> n;
    string s, t;
    cin >> s >> t;
    vec.push_back(0);
    for (int i=0; i<n; i++)
    {
        if (i && t[i]!=t[i-1])
        {
            sz++;
            vec.push_back(state);
            ind[sz]=(state==2?ind[sz-1]:sz);
            state=0;
        }
        if (state%2==0 && s[i]==t[i])
            state++;
        else if (state<2 && s[i]!=t[i])
            state+=2;
    }
    sz++;
    vec.push_back(state);
    ind[sz]=(state==2?ind[sz-1]:sz);
    for (int i=1; i<=sz; i++)
    {
        if (i&1)
            dp[i]=mindp1[i-1]+i/2+1;
        else
            dp[i]=mindp2[i-1]+i/2+1;
        dp[i]=min(dp[i], dp[ind[i]]+(i-ind[i])/2+1);
        if (vec[i]==1)
            dp[i]=min(dp[i], dp[i-1]);
        dp1[i]=dp[i]-i/2;
        dp2[i]=dp[i]-(i+1)/2;
        mindp1[i]=min(mindp1[i-1], dp1[i]);
        mindp2[i]=min(mindp2[i-1], dp2[i]);
    }
    cout << dp[sz];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 464 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 464 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 448 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 5 ms 4524 KB Output is correct
8 Correct 21 ms 32152 KB Output is correct
9 Correct 21 ms 32164 KB Output is correct
10 Correct 22 ms 32152 KB Output is correct
11 Correct 22 ms 32152 KB Output is correct
12 Correct 7 ms 4528 KB Output is correct
13 Correct 6 ms 4520 KB Output is correct
14 Correct 6 ms 5040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 464 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -