Submission #850238

# Submission time Handle Problem Language Result Execution time Memory
850238 2023-09-16T07:51:11 Z Tai_xiu Selotejp (COCI20_selotejp) C++14
70 / 110
1000 ms 11504 KB
#include <bits/stdc++.h>

using namespace std;
int n,m;
char a[1003][11];
vector<int>lt[1003],lt1[1003];
int dp[1003][1<<10],gt[1024][1024],val[1024];
void init()
{
    for (int i=0;i<(1<<m);i++){
          int tam=i;
          int cnt=0;
            if (tam&1)
                cnt++;
            for (int j=1;j<m;j++){
                if (((i>>j)&1) && (((i>>(j-1))&1)==0))
                    cnt++;
            }
        val[i]=cnt;
    }
    for (int i=0;i<(1<<m);i++){
        for (int j=0;j<(1<<m);j++){
            int tam=j,cnt=0;
            for (int k=0;k<m;k++){
                if (((i>>k)&1)==0 && ((j>>k)&1)==1){
                    cnt++;
                    tam^=(1<<k);
                }
            }
            gt[i][j]=val[tam]+cnt;
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n>>m;
    init();
   for (int i=0;i<=n;i++){
    for (int j=0;j<(1<<m);j++)
        dp[i][j]=1e9;
   }
    for (int i=1;i<=n;i++){
        for (int j=0;j<m;j++)
            cin>>a[i][j];
    }
    for (int i=0;i<m;i++)
        a[n+1][i]='.';
    for( int i=1;i<=n;i++){
        for (int j=0;j<(1<<m);j++){
              bool kt=true;
            for (int k=0;k<m;k++){
                if (((  j>>k)&1)==1 && a[i][k]=='.' )
                {
                    kt=false;
                    break;
                }
                if ((((j>>k)&1)==0) && a[i+1][k]=='.' && a[i][k]=='#'){
                    kt=false;
                    break;
                }
            }
            if (kt){
                lt[i].push_back(j);
                int tam=j;
                for (int k=0;k<m;k++){
                if (((j>>k)&1)==0 && a[i][k]=='.')
                    tam|=(1<<k);
                }
                lt1[i].push_back(tam);

            }
        }
    }
/*
    for (int i=1;i<=n;i++){
        for (int j:lt[i])
            cout<<j<<" ";
        cout<<endl;
    }

    10 11 14 15
    10 11 14 15
    2 3 6 7 10 11 14 15
    for (int i=2;i<=n;i++){
        for (int mask:lt[i]){
            for (int premask:)
        }
    }
   cout<<dp[n][(1<<m)-1];*/
   /*
   for (int i=1;i<=n;i++){
        for (int mask:lt[i]){
            int tam=mask;
            for (int j=0;j<m;j++){
                if (((mask>>j)&1)==0 && a[i][j]=='.')
                    tam|=(1<<j);
            }
            lt1[i].push_back(tam);
        }
   }*/
   /*
     for (int i=1;i<=n;i++){
        for (int j:lt1[i])
            cout<<j<<" ";
        cout<<endl;
    }*/
    for (int i=0;i<lt[1].size();i++){
        dp[1][lt1[1][i]]=val[lt[1][i]];
    }
    for (int i=2;i<=n;i++){
        for (int mask=0;mask<lt[i].size();mask++){
            for (int premask=0;premask<lt[i-1].size();premask++){
                dp[i][lt1[i][mask]]=min(dp[i][lt1[i][mask]],dp[i-1][lt1[i-1][premask]]+gt[lt1[i-1][premask]][lt[i][mask]]);
            }
        }
    }
    cout<<dp[n][(1<<m)-1];
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:110:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  110 |     for (int i=0;i<lt[1].size();i++){
      |                  ~^~~~~~~~~~~~~
Main.cpp:114:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  114 |         for (int mask=0;mask<lt[i].size();mask++){
      |                         ~~~~^~~~~~~~~~~~~
Main.cpp:115:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  115 |             for (int premask=0;premask<lt[i-1].size();premask++){
      |                                ~~~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4696 KB Output is correct
2 Correct 26 ms 8276 KB Output is correct
3 Correct 5 ms 8284 KB Output is correct
4 Correct 10 ms 8400 KB Output is correct
5 Correct 28 ms 8788 KB Output is correct
6 Correct 27 ms 8540 KB Output is correct
7 Correct 27 ms 8532 KB Output is correct
8 Correct 25 ms 8272 KB Output is correct
9 Correct 27 ms 8376 KB Output is correct
10 Correct 27 ms 8532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 4796 KB Output is correct
2 Correct 20 ms 4796 KB Output is correct
3 Correct 21 ms 4700 KB Output is correct
4 Correct 21 ms 4700 KB Output is correct
5 Correct 20 ms 4700 KB Output is correct
6 Correct 20 ms 4948 KB Output is correct
7 Correct 2 ms 4700 KB Output is correct
8 Correct 20 ms 4812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4696 KB Output is correct
2 Correct 26 ms 8276 KB Output is correct
3 Correct 5 ms 8284 KB Output is correct
4 Correct 10 ms 8400 KB Output is correct
5 Correct 28 ms 8788 KB Output is correct
6 Correct 27 ms 8540 KB Output is correct
7 Correct 27 ms 8532 KB Output is correct
8 Correct 25 ms 8272 KB Output is correct
9 Correct 27 ms 8376 KB Output is correct
10 Correct 27 ms 8532 KB Output is correct
11 Correct 20 ms 4796 KB Output is correct
12 Correct 20 ms 4796 KB Output is correct
13 Correct 21 ms 4700 KB Output is correct
14 Correct 21 ms 4700 KB Output is correct
15 Correct 20 ms 4700 KB Output is correct
16 Correct 20 ms 4948 KB Output is correct
17 Correct 2 ms 4700 KB Output is correct
18 Correct 20 ms 4812 KB Output is correct
19 Correct 2 ms 6236 KB Output is correct
20 Correct 6 ms 8568 KB Output is correct
21 Correct 12 ms 8540 KB Output is correct
22 Correct 26 ms 8528 KB Output is correct
23 Correct 25 ms 8536 KB Output is correct
24 Correct 28 ms 8400 KB Output is correct
25 Correct 29 ms 8540 KB Output is correct
26 Correct 109 ms 9044 KB Output is correct
27 Execution timed out 1026 ms 11504 KB Time limit exceeded
28 Halted 0 ms 0 KB -