QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#596885#5254. DifferencesQHhee004#TL 0ms0kbC++172.1kb2024-09-28 16:38:262024-09-28 16:38:26

Judging History

你现在查看的是最新测评结果

  • [2024-09-28 16:38:26]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-09-28 16:38:26]
  • 提交

answer

#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <cmath>
#include <time.h>
#define chmx(x, y) x=max(x,y)
#define chmn(x, y) x=min(x,y)
//#define x first
//#define y second
using namespace std;
const int N = 2e5 + 5;
const int P = 131;
const int M = 1e6 + 10;
const int mod = 123456789;
const int INF = 0x3f3f3f3f;
typedef long long ll;
typedef pair<ll, ll>PII;
int n, m, k, ans,d[100010];
bool st[100010];
int cnt[100010][4],pre[100010],nxt[100010];
string s[100010];
int Dis(string &a, string &b) {
    int res = 0;
    for (int i = 0; i < m; i++)
        res += (a[i] != b[i]);
    return res;
}
int Q[N];
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    srand(time(0));
    cin >> n >> m >> k;
    for (int i = 0; i < n; i++)cin >> s[i];
    for(int i=0; i<n; i++) {
    	for(int j=0; j<m; j++) {
    		cnt[j][s[i][j]-'A']++;
		}
	}
	for(int i=0; i<n; i++) {
		ll sum=0;
		for(int j=0; j<m; j++)
			for(int k=0; k<4; k++)
				if(s[i][j]-'A'!=k)sum=sum+cnt[j][k];
		if(sum!=1ll*(n-1)*k)st[i]=1;
	}
	for(int i=0; i<n; i++)swap(d[rand()%n],d[rand()%n]);
	for(int i=0; i<n; i++)d[i]=i,pre[i]=i-1,nxt[i]=i+1;
	int l=1,r=0,g=0;
	bool flag=0;
	while(g!=n) {
		if(l<=r) {
			while(l<=r) {
				int now=Q[l];
				for(int i=g; i!=n; i=nxt[i]) {
					int dis=Dis(s[d[i]],s[d[now]]);
					if(dis!=k) {
						st[d[i]]=1;
						pre[nxt[i]]=pre[i];
						nxt[pre[i]]=nxt[i];
						Q[++r]=i;
					}
					nxt[n-1]=n;
				}
				l++;
			}
		} else {
			if(st[d[g]]) {
				g=nxt[g];continue;
			}
			for(int i=nxt[g]; i!=n; i=nxt[i]) {
				int dis=Dis(s[d[i]],s[d[g]]);
				if(dis!=k){
					st[d[k]]=st[d[i]]=1;
					pre[nxt[i]]=pre[i];
					nxt[pre[i]]=nxt[i];
					Q[++r]=i;
					flag=0;
				} 
			}
			if(flag){cout<<d[k]+1<<'\n';break;}
			nxt[n-1]=n;
			g=nxt[g];
		}
	}
	if(!flag) {
		for(int i=0; i<n; i++) {
			if(!st[i]) {
				cout<<i+1<<'\n';
				break;
			}
		}
	}
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

3585 4096 2048
ABBBBBBAABAAAAAAAAAAAAABAABABBBABABAAAAABABAAAABAABAABBABBAABAABABBABAABBABBABABABBAAAABBABAABBBBABBBAABBBBBABAABAAABAAABBBBAAAABAABAABABABABBBBBABAAABAAABBAABABBABAABBAABBAABABBBBAABAAAABAABBABAAABBAAAAAABAABBABBABAABABBBAABABBABABBBAAAAABBBABABABBAABAAAABBBBABABAABBBABABABBAABBBABAB...

output:


result: