Submission #120122

# Submission time Handle Problem Language Result Execution time Memory
120122 2019-06-23T12:59:12 Z OptxPrime Sajam (COCI18_sajam) C++11
15 / 90
5000 ms 23976 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[2010];
    unsigned long long dist[2010][2010][2];
    vector<unsigned long long>block[2010];

    /// 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<2*n;i++ ){
           // cout<<i<<" lalala  " <<endl;
            if( i<n )
            cin>>s[i];
            else s[i]=kontra( s[i-n] );
        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;
            }
        }
    }

    //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;
            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: In function 'long long unsigned int hamming(int, int)':
sajam.cpp:29: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:39: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:52:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for( int i=0;i<2*n;i++ ){
                  ~^~~~
sajam.cpp:54:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if( i<n )
                 ~^~
sajam.cpp:77:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for( int i=0;i<n;i++ ){
                  ~^~
sajam.cpp:79:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for( int j=0;j<n;j++ ){
                      ~^~
sajam.cpp:98:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for( int i=0;i<n;i++ ){
                  ~^~
sajam.cpp:100:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for( int j=0;j<n;j++ ){
                      ~^~
sajam.cpp:103:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for( int k=0;k<n;k++ ){
                          ~^~
sajam.cpp:114:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for( int k=0;k<n;k++ ){
                          ~^~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 640 KB Output is correct
2 Correct 132 ms 5412 KB Output is correct
3 Correct 230 ms 7544 KB Output is correct
4 Correct 1160 ms 18936 KB Output is correct
5 Correct 235 ms 7672 KB Output is correct
6 Correct 67 ms 3712 KB Output is correct
7 Correct 724 ms 7032 KB Output is correct
8 Correct 4443 ms 19792 KB Output is correct
9 Correct 71 ms 2304 KB Output is correct
10 Correct 4635 ms 20088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 640 KB Output is correct
2 Correct 4 ms 868 KB Output is correct
3 Incorrect 5 ms 896 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 687 ms 13772 KB Output is correct
2 Correct 927 ms 16376 KB Output is correct
3 Correct 530 ms 11768 KB Output is correct
4 Correct 452 ms 10488 KB Output is correct
5 Correct 1302 ms 18808 KB Output is correct
6 Correct 273 ms 8184 KB Output is correct
7 Correct 635 ms 14072 KB Output is correct
8 Correct 738 ms 15160 KB Output is correct
9 Correct 366 ms 5112 KB Output is correct
10 Execution timed out 5031 ms 23928 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 1053 ms 17532 KB Output is correct
2 Correct 994 ms 17176 KB Output is correct
3 Correct 449 ms 10876 KB Output is correct
4 Correct 628 ms 13304 KB Output is correct
5 Correct 681 ms 14072 KB Output is correct
6 Correct 1439 ms 22080 KB Output is correct
7 Correct 189 ms 6648 KB Output is correct
8 Correct 589 ms 13436 KB Output is correct
9 Correct 2338 ms 14548 KB Output is correct
10 Execution timed out 5019 ms 23976 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 491 ms 10872 KB Output is correct
2 Correct 555 ms 10988 KB Output is correct
3 Incorrect 1905 ms 22716 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1868 ms 23288 KB Output is correct
2 Correct 1712 ms 22400 KB Output is correct
3 Incorrect 1684 ms 19916 KB Output isn't correct
4 Halted 0 ms 0 KB -