답안 #395539

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
395539 2021-04-28T13:19:36 Z MrRobot_28 Selotejp (COCI20_selotejp) C++17
0 / 110
2 ms 204 KB
#include<bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define sz(a) (int)a.size()
#define ll long long
#define ld long double

signed main()
{
    //ifstream cin("286.txt");
//    ios_base::sync_with_stdio(0);
  //  cin.tie(0);
    //cout.tie(0);
    int  n, m;
    cin >> n >> m;
    char A[n][m];
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < m; j++)
        {
            cin >> A[i][j];
        }
    }
    vector <int> dp((1 << m), 1e9), dp1((1 << m), 1e9);
    dp[0] = 0;
    for(int i = 0; i < n; i++)
    {
        fill(dp1.begin(), dp1.end(), 1e9);
        int msk = 0;
        for(int j = 0; j < m; j++)
        {
            msk += (A[i][j] == '#') * (1 << j);
        }
        for(int j = 0; j < (1 << m); j++)
        {
            dp1[msk & j] = min(dp1[msk & j], dp[j]);
        }
        for(int j = (1 << m) - 1; j >= 0; j--)
        {
            for(int t = 0; t < m; t++)
            {
                if((1 << t) & j)
                {
                    continue;
                }
                dp1[j] = min(dp1[j], dp1[j + t]);
            }
        }
        for(int j = 0; j < (1 << m); j++)
        {
            for(int t = 0; t < m; t++)
            {
                if(!((1 << t) & j))
                {
                    continue;
                }
                dp1[j] = min(dp1[j], dp1[j - (1 << t)] + 1);
            }
        }
       /* for(int j = 0; j < (1 << m); j++)
        {
            cout << dp1[j] << " ";
        }
        cout << "\n";
     */   for(int j = 0; j < (1 << m); j++)
        {
            if((j & msk) != j)
            {
   //             cout << "A " << j << "\n";
                dp1[j] = 1e9;
                continue;
            }
            int last = -2;
            int cnt = 0;
            for(int t = 0; t < m; t++)
            {
                if((1 << t) & j)
                {
                    continue;
                }
                if((1 << t) & msk)
                {
                    if(last < t - 1)
                    {
                        cnt++;
                    }
                    last = t;
                }
            }
            dp1[j] += cnt;
        }
        for(int j = 0; j < (1 << m); j++)
        {
            dp[j] = dp1[j];
        }
        //cout << msk << " ";
        //cout << dp[0] << "\n";
    }
    int msk = 0;
    for(int i= 0; i < m; i++)
    {
        msk += (A[n - 1][i] == '#') * (1 << i);
    }
    int ans = 1e9;
    for(int j = 0; j < (1 << m); j++)
    {
        if((msk & j) != j)
        {
            continue;
        }
        ans = min(ans, dp[j]);
    }
    cout << ans;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -