# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
120123 |
2019-06-23T13:01:30 Z |
OptxPrime |
Sajam (COCI18_sajam) |
C++11 |
|
328 ms |
23288 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:109:8: warning: "/*" within comment [-Wcomment]
/* if( i==0 ){
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++ ){
~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
640 KB |
Output is correct |
2 |
Correct |
36 ms |
5368 KB |
Output is correct |
3 |
Correct |
64 ms |
7544 KB |
Output is correct |
4 |
Correct |
296 ms |
19020 KB |
Output is correct |
5 |
Correct |
65 ms |
7672 KB |
Output is correct |
6 |
Correct |
23 ms |
3708 KB |
Output is correct |
7 |
Correct |
58 ms |
7032 KB |
Output is correct |
8 |
Correct |
294 ms |
19776 KB |
Output is correct |
9 |
Correct |
11 ms |
2304 KB |
Output is correct |
10 |
Correct |
293 ms |
20016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
640 KB |
Output is correct |
2 |
Correct |
3 ms |
768 KB |
Output is correct |
3 |
Incorrect |
3 ms |
896 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
159 ms |
13760 KB |
Output is correct |
2 |
Correct |
204 ms |
16252 KB |
Output is correct |
3 |
Correct |
123 ms |
11768 KB |
Output is correct |
4 |
Correct |
100 ms |
10568 KB |
Output is correct |
5 |
Correct |
248 ms |
18648 KB |
Output is correct |
6 |
Correct |
65 ms |
8056 KB |
Output is correct |
7 |
Correct |
146 ms |
13532 KB |
Output is correct |
8 |
Correct |
165 ms |
14584 KB |
Output is correct |
9 |
Correct |
34 ms |
5112 KB |
Output is correct |
10 |
Correct |
320 ms |
22904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
232 ms |
17528 KB |
Output is correct |
2 |
Correct |
212 ms |
17152 KB |
Output is correct |
3 |
Correct |
112 ms |
10872 KB |
Output is correct |
4 |
Correct |
149 ms |
13272 KB |
Output is correct |
5 |
Correct |
154 ms |
14072 KB |
Output is correct |
6 |
Correct |
296 ms |
22120 KB |
Output is correct |
7 |
Correct |
48 ms |
6392 KB |
Output is correct |
8 |
Correct |
137 ms |
12920 KB |
Output is correct |
9 |
Correct |
158 ms |
13944 KB |
Output is correct |
10 |
Correct |
328 ms |
22892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
108 ms |
10872 KB |
Output is correct |
2 |
Correct |
107 ms |
11000 KB |
Output is correct |
3 |
Incorrect |
318 ms |
22848 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
317 ms |
23288 KB |
Output is correct |
2 |
Correct |
300 ms |
22428 KB |
Output is correct |
3 |
Incorrect |
263 ms |
19728 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |