This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(8962);
int n, m, k;
char a[4105][4105];
bitset<4105> bs[4105];
int ff(int x, int y)
{
return (bs[x] ^ bs[y]).count();
}
bool mna(int x, int y)
{
int xx = ff(x, y);
if (xx == k)
return true;
return false;
}
bool candi[4105];
int df[4105];
void muta(int x, int y)
{
vector<int> dife;
for (int i = 1; i <= m; i++)
{
if (a[x][i] != a[y][i])
dife.push_back(i);
}
for (int i = 1; i <= n; i++)
{
for (auto it : dife)
{
if (a[i][it] != a[x][it])
df[i]--;
if (a[i][it] != a[y][it])
df[i]++;
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> m >> k;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
cin >> a[i][j];
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
{
if (a[i][j] == 'C')
bs[i][j] = 1;
}
if (k >= 20)
{
vector<int> noduri = {1};
for (int i = 2; i <= n; i++)
{
bool boo = true;
for (auto it : noduri)
{
if (!mna(i, it))
{
boo = false;
break;
}
}
if (boo)
noduri.push_back(i);
}
for (auto i : noduri)
{
bool nah = false;
for (int j = 1; j <= n; j++)
{
if (j != i and !mna(i, j))
{
nah = true;
break;
}
}
if (!nah)
{
cout << i;
return 0;
}
}
}
else
{
for (int i = 1; i <= n; i++)
candi[i] = true;
int cur = 1;
for (int i = 1; i <= n; i++)
df[i] = ff(1, i);
while (true)
{
//cout << cur << endl;
bool nah = false;
for (int i = 1; i <= n; i++)
if (i != cur and df[i] != k)
nah = true;
if (!nah)
{
cout << cur;
return 0;
}
for (int i = 1; i <= n; i++)
{
if (df[i] != k)
candi[i] = false;
}
for (int i = 1; i <= n; i++)
if (df[i] == k and candi[i])
{
int mv = i;
muta(cur, mv);
cur = mv;
break;
}
}
}
return 0;
}
# | 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... |