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;
#define int long long
#define double long double
#define FOR(i, l, r, d) for(int i=(l); i<=(r); i+=(d))
#define szof(x) ((int)(x).size())
#define vi vector<int>
#define pii pair<int,int>
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define mkp make_pair
const int INF = 2147483647;
const int LNF = INF*INF;
const int MOD = 1000000007;
const int mod = 998244353;
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
const int MAX = 4110;
int n, m, k;
string str[MAX];
int dif[MAX][MAX];
bool rem[MAX];
int rc;
int res;
void find_dif(int u, int v){
if(dif[u][v] != -1) return;
int cnt = 0;
FOR(i, 0, m-1, 1){
if(str[u][i] != str[v][i]){
cnt++;
}
}
dif[u][v] = dif[v][u] = cnt;
if(u!=v and dif[u][v]!=k){
rc -= rem[u];
rem[u] = 0;
rc -= rem[v];
rem[v] = 0;
}
}
int randint(int r){
int a = rand();
int b = rand();
return ((a<<12) ^ b) % r;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
srand(time(NULL));
cin>>n>>m>>k;
FOR(i, 1, n, 1){
cin>>str[i];
}
FOR(i, 1, n, 1){
FOR(j, 1, n, 1){
dif[i][j] = -1;
}
}
FOR(i, 1, n, 1){
rem[i] = 1;
}
rc = n;
while(rc > 1){
int rd = randint(n*n);
int u = rd/n + 1;
int v = rd%n + 1;
if(rem[u]==0 and rem[v]==0){
continue;
}
find_dif(u, v);
}
FOR(i, 1, n, 1){
if(rem[i]==1){
res = i;
}
}
cout<<res<<'\n';
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... |