# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
120119 |
2019-06-23T12:19:07 Z |
OptxPrime |
Sajam (COCI18_sajam) |
C++11 |
|
298 ms |
24312 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
long long n,k;
string s[2010];
long long dist[2010][2010][2];
vector<long long>block[2010];
/// ovo bi trebalo da rjesi sve osim K=N
long long hamming( int a, int b )
{
long long ans=0;
for( int i=0;i<block[a].size();i++ ){
// cout << a << " " << b << " " << i << " "<< block[a][i] << " tarik " <<endl;
ans+= __builtin_popcount( 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] );
long long curr=0;
for( long long j=0;j<=n;j++ ){
// cout <<j<< " aa " <<endl;
if( (j%64LL==0 && j>0) || ( j==n ) ){
// if( i==0 ) cout<< j << " " <<curr << " wtf "<<endl;
block[i].pb( curr );
curr=0;
if(j==n) break;
}
if( s[i][j]=='x' ) {
curr|=( 1<<( j%64LL ) );
// cout << i << " " << j << " " << ( j%64 ) << " namir " <<endl;
}
}
}
//cout << block[1][0] << " eto " <<endl;
long long res=100000000;
for( int i=0;i<n;i++ ){
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);
}
//cout<<res<<endl;
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 int hamming(int, int)':
sajam.cpp:26:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for( int i=0;i<block[a].size();i++ ){
~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
640 KB |
Output is correct |
2 |
Correct |
32 ms |
5496 KB |
Output is correct |
3 |
Correct |
55 ms |
7800 KB |
Output is correct |
4 |
Correct |
240 ms |
19900 KB |
Output is correct |
5 |
Correct |
58 ms |
8056 KB |
Output is correct |
6 |
Correct |
19 ms |
3840 KB |
Output is correct |
7 |
Correct |
51 ms |
7416 KB |
Output is correct |
8 |
Correct |
265 ms |
20620 KB |
Output is correct |
9 |
Correct |
9 ms |
2304 KB |
Output is correct |
10 |
Correct |
266 ms |
20860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
640 KB |
Output is correct |
2 |
Correct |
3 ms |
768 KB |
Output is correct |
3 |
Correct |
3 ms |
1024 KB |
Output is correct |
4 |
Correct |
2 ms |
640 KB |
Output is correct |
5 |
Correct |
3 ms |
768 KB |
Output is correct |
6 |
Incorrect |
2 ms |
768 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
138 ms |
14328 KB |
Output is correct |
2 |
Correct |
179 ms |
17200 KB |
Output is correct |
3 |
Correct |
105 ms |
12280 KB |
Output is correct |
4 |
Correct |
89 ms |
10876 KB |
Output is correct |
5 |
Correct |
227 ms |
19476 KB |
Output is correct |
6 |
Incorrect |
58 ms |
8440 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
200 ms |
18196 KB |
Output is correct |
2 |
Correct |
197 ms |
17900 KB |
Output is correct |
3 |
Correct |
95 ms |
11256 KB |
Output is correct |
4 |
Correct |
136 ms |
13816 KB |
Output is correct |
5 |
Correct |
141 ms |
14636 KB |
Output is correct |
6 |
Incorrect |
284 ms |
22936 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
99 ms |
11256 KB |
Output is correct |
2 |
Correct |
102 ms |
11384 KB |
Output is correct |
3 |
Correct |
287 ms |
23644 KB |
Output is correct |
4 |
Correct |
60 ms |
8568 KB |
Output is correct |
5 |
Correct |
98 ms |
11512 KB |
Output is correct |
6 |
Incorrect |
281 ms |
22932 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
298 ms |
24312 KB |
Output is correct |
2 |
Correct |
280 ms |
23304 KB |
Output is correct |
3 |
Correct |
245 ms |
20728 KB |
Output is correct |
4 |
Correct |
130 ms |
13560 KB |
Output is correct |
5 |
Correct |
127 ms |
13816 KB |
Output is correct |
6 |
Incorrect |
136 ms |
14456 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |