Submission #120128

# Submission time Handle Problem Language Result Execution time Memory
120128 2019-06-23T13:46:25 Z OptxPrime Sajam (COCI18_sajam) C++11
60 / 90
5000 ms 23132 KB
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include<queue>
#include<string.h>
#include<map>

using namespace std;
#define pb push_back
#define mp make_pair
#define tl TypeLetter
#define uc UndoCommands
#define gl GetLetter

  unsigned long long n,k;
  unsigned long long c=64;
    string s[4010];
    unsigned long long dist[4010][4010][2];
    unsigned long long spec[4010][2];
    vector<unsigned long long>block[4010];

    /// ovo bi trebalo da rjesi sve osim K=N

    /// nesto ne valja, mozda mi treba unsigned long long

    unsigned long long hamming(  int a, int b )
    {
        unsigned long long ans=0;
      for( int i=0;i<block[a].size();i++ ){
       //     cout << a << " " << b << " " << i << " "<< block[a][i] << " tarik " <<endl;
        ans+= (unsigned long long)(__builtin_popcountll( block[a][i]^block[b][i] ));
      }
      return ans;
    }
    string kontra( string s )
    {
        string ans="";
        ans.resize(n);
        for( int i=0;i<n;i++ ){
            if( s[i]=='x' ) ans[i]='o';
            else ans[i]='x';
        }
        return ans;
    }

int main()
{

    cin>>n>>k;
    //cout << kontra( "xoxx" )<<endl;
  // // cout<<"  pasha " <<endl;
    for( int i=0;i<4*n;i++ ){
           // cout<<i<<" lalala  " <<endl;
            if( i<n )
            cin>>s[i];
            else if( i<2*n ) s[i]=kontra( s[i-n] );
            else if( i<3*n ){   /// ubacujemo izmjene
                    if( n!=k ) break;
                s[i]=s[0];
                if(s[i][i-2*n] == 'x') s[i][i-2*n]='o';
                else s[i][ i-2*n ]='x';
            }
            else{   /// opet izmjenr
                s[i]= kontra( s[0] );
                if( s[i][ i-3*n ]=='x' ) s[i][ i-3*n ]='o';
                    else s[i][ i-3*n ]='x';
            }
        unsigned long long curr=0;
        for( unsigned long long j=0;j<=n;j++ ){
             //   cout <<j<< " aa " <<endl;
             /// c je velicina bloka, 64
            if( (j%c==0 && j>0) || ( j==n ) ){
            //    if( i==0 ) cout<< j << " " <<curr << " wtf "<<endl;
                block[i].pb( curr );
                curr=0LL;
        if(j==n) break;
            }
            if( s[i][j]=='x' ) {
                    curr|=( 1LL<<( j%c ) );
              //      cout << i << " " << j << " " << ( j%64 ) << " namir " <<endl;
            }
        }
    }
    /*
3 3
xxo
xox
oox
    */
    /// treba jos postaviti od prvog stringa sve izmjene
   // cout << block[3*n][0] << " " << block[3*n+1][2] << " kontas " <<endl;
   /// dobri svi blokovi izgleda
   /* string curr=s[0];
    for( int i=0;i<n;i++ ){

    }*/

    //cout << block[1][0] << " eto " <<endl;
    unsigned long long res=100000000;

    for( int i=0;i<n;i++ ){
           unsigned long long sum0=0,sum1=0;
        for( int j=0;j<n;j++ ){
                if( i==j ) continue;

                if( n==k && i==0 ){ /// ovo je specijalan slucaj kad mozemo u svakom redu promjenit
            /// ne valja mi ovo

                        for( int p=0;p<n;p++ ){
                                unsigned long long sum0=0,sum1=0;
                            for( int a=0;a<n;a++ ){
                            spec[a][0]=spec[a][1]=100000000;
                        spec[a][0]= hamming( 2*n+p,a );
                        spec[a][0]=min( spec[a][0], hamming( 2*n+p,n+a ) );
                        spec[a][1]= hamming( 3*n+p,a );
                        spec[a][1]=min(spec[a][1],hamming( 3*n+p,n+a ));
                        sum0+=spec[a][0];
                        sum1+=spec[a][1];
                    }
                    if( sum0 <= k || sum1<=k ){
                   //     cout << sum0 <<"  " << sum1 << " bee " <<endl;
                    cout<<"DA"<<endl;
                    return 0;
                }
                        }


                }
            dist[i][j][0] = hamming( i,j );
           // string tmp= kontra(  ) ;
            dist[i][j][0]=min( dist[i][j][0], hamming( i,j+n ) );
            dist[i][j][1]= hamming( i+n,j );
            dist[i][j][1]=min( dist[i][j][1], hamming( i+n,j+n ));
         //   cout<<i << " " << j << " " << dist[i][j][0] << " " << dist[i][j][1] << " tjt " <<endl;
            sum0+=dist[i][j][0];
            sum1+=dist[i][j][1];
        }
        res=min( res,sum0 );
        res=min(res,sum1);
    }
 //   for( int i=0;i<n;i++ ) cout<<block[i][0] << " rastika " <<endl;
   // cout<<res<<endl;
    if( res<=k ) cout<<"DA"<<endl;
    else cout<<"NE"<<endl;

   /* for( int i=0;i<n;i++ ){

        for( int j=0;j<n;j++ ){
                 if(i==j)continue;
                unsigned long long tmp=0,anss;
            for( int k=0;k<n;k++ ){
                if( s[i][k]!=s[j][k] ) tmp++;
            }
            anss=tmp;
            tmp=0;
            string t=kontra( s[j] );
       /* if( i==0 ){
            cout<<s[j]<<endl;
            cout<<t<<endl;
            cout<<" roogibe  "  <<endl;
         }
            for( int k=0;k<n;k++ ){
                if( s[i][k]!=t[k] ) tmp++;
            }
            anss=min( anss, tmp );
       //     cout<<i<<" " << j << " " << dist[i][j][0] <<  " "<< anss << " aaa bukovica " <<endl;
            /// ne poklapa se dist[i][j] uvijek sa anss iz nekog razloga.
         }
    }*/


    return 0;
}

/*
5
1
2
1

2
2
*/










Compilation message

sajam.cpp:158:8: warning: "/*" within comment [-Wcomment]
        /* if( i==0 ){
         
sajam.cpp: In function 'long long unsigned int hamming(int, int)':
sajam.cpp:30:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for( int i=0;i<block[a].size();i++ ){
                    ~^~~~~~~~~~~~~~~~
sajam.cpp: In function 'std::__cxx11::string kontra(std::__cxx11::string)':
sajam.cpp:40:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for( int i=0;i<n;i++ ){
                      ~^~
sajam.cpp: In function 'int main()':
sajam.cpp:53:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for( int i=0;i<4*n;i++ ){
                  ~^~~~
sajam.cpp:55:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if( i<n )
                 ~^~
sajam.cpp:57:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             else if( i<2*n ) s[i]=kontra( s[i-n] );
                      ~^~~~
sajam.cpp:58:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             else if( i<3*n ){   /// ubacujemo izmjene
                      ~^~~~
sajam.cpp:102:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for( int i=0;i<n;i++ ){
                  ~^~
sajam.cpp:104:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for( int j=0;j<n;j++ ){
                      ~^~
sajam.cpp:110:39: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                         for( int p=0;p<n;p++ ){
                                      ~^~
sajam.cpp:112:43: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                             for( int a=0;a<n;a++ ){
                                          ~^~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 768 KB Output is correct
2 Correct 35 ms 5500 KB Output is correct
3 Correct 61 ms 7672 KB Output is correct
4 Correct 248 ms 19204 KB Output is correct
5 Correct 65 ms 7928 KB Output is correct
6 Correct 21 ms 3832 KB Output is correct
7 Correct 54 ms 7384 KB Output is correct
8 Correct 276 ms 19824 KB Output is correct
9 Correct 11 ms 2432 KB Output is correct
10 Correct 280 ms 20216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 768 KB Output is correct
2 Correct 13 ms 888 KB Output is correct
3 Correct 3 ms 640 KB Output is correct
4 Correct 2 ms 640 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 7 ms 896 KB Output is correct
7 Correct 27 ms 1152 KB Output is correct
8 Correct 7 ms 896 KB Output is correct
9 Correct 16 ms 1024 KB Output is correct
10 Correct 15 ms 1024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 159 ms 13916 KB Output is correct
2 Correct 189 ms 16500 KB Output is correct
3 Correct 117 ms 11896 KB Output is correct
4 Correct 99 ms 10744 KB Output is correct
5 Correct 249 ms 18836 KB Output is correct
6 Correct 64 ms 8316 KB Output is correct
7 Correct 140 ms 13688 KB Output is correct
8 Correct 163 ms 14792 KB Output is correct
9 Correct 34 ms 5152 KB Output is correct
10 Correct 315 ms 23132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 214 ms 17832 KB Output is correct
2 Correct 216 ms 17272 KB Output is correct
3 Correct 105 ms 10972 KB Output is correct
4 Correct 143 ms 13560 KB Output is correct
5 Correct 154 ms 14248 KB Output is correct
6 Correct 286 ms 22136 KB Output is correct
7 Correct 46 ms 6520 KB Output is correct
8 Correct 134 ms 13032 KB Output is correct
9 Correct 159 ms 14212 KB Output is correct
10 Correct 318 ms 23032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 5086 ms 2808 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5084 ms 6008 KB Time limit exceeded
2 Halted 0 ms 0 KB -