답안 #120149

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
120149 2019-06-23T14:59:25 Z OptxPrime Sajam (COCI18_sajam) C++11
60 / 90
5000 ms 19676 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];

    /// TLE, 60/90 DOBIJAM.
    /// Dal su ovako i drugi rjesili? hamming distancom
    /// NALETIO SAM NA NEKO RJESENJE KO MOJE, PROVJERITI SLICNOSTI I RAZLIKE


    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;

    for( int i=0;i<4*n;i++ ){
            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;
            }
        }
    }


    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 ) break;
                    }
                    if( sum0 <= k || sum1<=k ){
                    cout<<"DA"<<endl;
                    return 0;
                }
                        }
                }
            dist[i][j][0] = hamming( i,j );
            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 ));
            sum0+=dist[i][j][0];
            sum1+=dist[i][j][1];
            if( sum0>k && sum1>k ) break;
        }
        res=min( res,sum0 );
        res=min(res,sum1);
    }
    if( res<=k ) cout<<"DA"<<endl;
    else cout<<"NE"<<endl;


    return 0;
}

/*
5
1
2
1

2
2
*/










Compilation message

sajam.cpp: In function 'long long unsigned int hamming(int, int)':
sajam.cpp:31: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:41: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:54:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if( i<n )
                 ~^~
sajam.cpp:56:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             else if( i<2*n ) s[i]=kontra( s[i-n] );
                      ~^~~~
sajam.cpp:57:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             else if( i<3*n ){   /// ubacujemo izmjene
                      ~^~~~
sajam.cpp:88:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for( int i=0;i<n;i++ ){
                  ~^~
sajam.cpp:90:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for( int j=0;j<n;j++ ){
                      ~^~
sajam.cpp:96:39: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                         for( int p=0;p<n;p++ ){
                                      ~^~
sajam.cpp:98:43: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                             for( int a=0;a<n;a++ ){
                                          ~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 768 KB Output is correct
2 Correct 36 ms 5624 KB Output is correct
3 Correct 60 ms 7928 KB Output is correct
4 Correct 252 ms 19576 KB Output is correct
5 Correct 63 ms 8060 KB Output is correct
6 Correct 20 ms 3960 KB Output is correct
7 Correct 22 ms 3712 KB Output is correct
8 Correct 69 ms 6904 KB Output is correct
9 Correct 7 ms 1660 KB Output is correct
10 Correct 70 ms 6904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 768 KB Output is correct
2 Correct 9 ms 896 KB Output is correct
3 Correct 3 ms 640 KB Output is correct
4 Correct 3 ms 640 KB Output is correct
5 Correct 2 ms 640 KB Output is correct
6 Correct 5 ms 896 KB Output is correct
7 Correct 16 ms 1024 KB Output is correct
8 Correct 5 ms 896 KB Output is correct
9 Correct 3 ms 896 KB Output is correct
10 Correct 3 ms 868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 126 ms 12424 KB Output is correct
2 Correct 164 ms 14804 KB Output is correct
3 Correct 97 ms 10612 KB Output is correct
4 Correct 89 ms 9968 KB Output is correct
5 Correct 199 ms 15912 KB Output is correct
6 Correct 60 ms 7800 KB Output is correct
7 Correct 132 ms 12796 KB Output is correct
8 Correct 161 ms 13688 KB Output is correct
9 Correct 17 ms 2788 KB Output is correct
10 Correct 81 ms 8156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 184 ms 14968 KB Output is correct
2 Correct 201 ms 15608 KB Output is correct
3 Correct 98 ms 10232 KB Output is correct
4 Correct 134 ms 13176 KB Output is correct
5 Correct 145 ms 13176 KB Output is correct
6 Correct 255 ms 19676 KB Output is correct
7 Correct 45 ms 6008 KB Output is correct
8 Correct 139 ms 12472 KB Output is correct
9 Correct 48 ms 5624 KB Output is correct
10 Correct 79 ms 8184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5065 ms 3296 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5079 ms 6500 KB Time limit exceeded
2 Halted 0 ms 0 KB -