이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,popcnt")
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>
int N,M,K;
namespace SMALL{
const int mxn = 4140;
int arr[mxn][mxn];
vector<int> v,cand;
const int magic = sqrt(mxn);
bitset<mxn> in;
const int lim = 1.95*CLOCKS_PER_SEC;
int st;
int dif(int a,int b){
int re = 0;
for(int i = 0;i<M;i++){
re += (arr[a][i] != arr[b][i]);
}
return re;
}
void collect(){
for(int i = 0;i<N;i++){
for(int j = i+1;j<N;j++){
if(dif(i,j) != K){
if(!in[i])v.push_back(i);
if(!in[j])v.push_back(j);
if(v.size()>=magic)return;
in[i] = in[j] = true;
}
}
if(!in[i]){
cout<<i+1;
exit(0);
}
}
return;
}
void solve(){
for(int i = 0;i<N;i++){
for(int j = 0;j<M;j++){
char c;
cin>>c;
arr[i][j] = c-'A';
}
}
collect();
for(int i = 0;i<N;i++){
if(in[i])continue;
bool flag = true;
for(auto &j:v){
if(dif(i,j) != K)flag = false;
}
if(flag)cand.push_back(i);
}
//assert(cand.size()<100);
for(auto &i:cand){
bool flag = true;
for(int j = 0;j<N;j++){
if(i == j)continue;
if(dif(i,j) != K){
flag = false;
break;
}
}
if(flag){
cout<<i+1;
return;
}
}
assert(false);
}
}
namespace TWO{
const int mxn = 4140;
bitset<mxn> dp[mxn];
string in;
int arr[mxn],pos[mxn];
void solve(){
for(int i = 0;i<N;i++)arr[i] = i;
srand(time(NULL));
random_shuffle(arr,arr+N);
for(int i = 0;i<N;i++)pos[arr[i]] = i;
for(int i = 0;i<N;i++){
cin>>in;
int now = pos[i];
for(int j = 0;j<M;j++){
if(in[j] == 'A')dp[now][j] = true;
}
}
/*
for(int i = 0;i<N;i++)cout<<arr[i]<<' ';cout<<endl;
for(int i = 0;i<N;i++){
for(int j = 0;j<M;j++)cout<<(dp[i][j]?'A':'C');
cout<<endl;
}
*/
for(int i = 0;i<N;i++){
bool flag = true;
for(int j = 0;j<N;j++){
if(i == j)continue;
//cout<<i<<','<<j<<":"<<(dp[i]^dp[j]).count()<<endl;
if(!flag)break;
if((dp[i]^dp[j]).count() != K)flag = false;
}
if(flag){
cout<<arr[i]+1;
return;
}
}
}
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);
cin>>N>>M>>K;
SMALL::solve();return 0;
if(N*M<=1e6)SMALL::solve();
else TWO::solve();
}
컴파일 시 표준 에러 (stderr) 메시지
genetics.cpp: In function 'void TWO::solve()':
genetics.cpp:121:29: warning: comparison of integer expressions of different signedness: 'std::size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
121 | if((dp[i]^dp[j]).count() != K)flag = false;
| ~~~~~~~~~~~~~~~~~~~~~~^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |