QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#547683#7686. The Phantom MenacerookiefyqWA 23ms160248kbC++142.1kb2024-09-05 01:57:592024-09-05 01:58:00

Judging History

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

  • [2024-10-08 14:11:03]
  • hack成功,自动添加数据
  • (/hack/941)
  • [2024-10-08 10:05:28]
  • hack成功,自动添加数据
  • (/hack/940)
  • [2024-10-07 19:51:15]
  • hack成功,自动添加数据
  • (/hack/938)
  • [2024-10-07 19:28:01]
  • hack成功,自动添加数据
  • (/hack/937)
  • [2024-10-07 17:16:32]
  • hack成功,自动添加数据
  • (/hack/936)
  • [2024-10-07 16:53:09]
  • hack成功,自动添加数据
  • (/hack/935)
  • [2024-10-07 16:22:17]
  • hack成功,自动添加数据
  • (/hack/934)
  • [2024-09-05 01:58:00]
  • 评测
  • 测评结果:WA
  • 用时:23ms
  • 内存:160248kb
  • [2024-09-05 01:57:59]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 2e6+999, B = 31;
string a[N];
vector<ull> hs[N];
int n, m, d[N], tot;
vector<pair<int, int>> e[N];
ull p[N];
ull gethash(int id, int l, int r){
	if(l > r) return 0;
	if(l == 0) return hs[id][r];
	return hs[id][r] - hs[id][l - 1] * p[r - l + 1];
}
bool work(int l){
	map<ull, int> mp;
	for(int i = 1; i <= tot; i++)
	    e[i].clear(), d[i] = 0;
	tot = 0;
	for(int i = 1; i <= n; i++){
		ull h1 = gethash(i, 0, l), h2 = gethash(i, l + 1, m - 1);
		int u, v;
		if(mp.count(h1)) u = mp[h1];
		else u = mp[h1] = ++tot;
		if(mp.count(h2)) v = mp[h2];
		else v = mp[h2] = ++tot;
		if(tot > n * 2) return 0;
		e[u].emplace_back(v, i);
		d[u]++, d[v]--;
	}
	for(int i = n + 1; i <= 2 * n; i++){
		ull h1 = gethash(i, 0, m - 1 - l - 1), h2 = gethash(i, m - 1 - l, m - 1);
		int u, v;
		if(mp.count(h1)) u = mp[h1];
		else u = ++tot;
		if(mp.count(h2)) v = mp[h2];
		else v = ++tot;
		if(tot > n * 2) return 0;
		e[u].emplace_back(v, i);
		d[u]++, d[v]--;		
	}
	for(int i = 1; i <= tot; i++)
	    if(d[i] != 0) return 0;
	return 1;    
}
vector<int> ans1, ans2;
void dfs(int u){
	while(e[u].size()){
		auto [v, id] = e[u].back();
		e[u].pop_back();
		dfs(v);
		if(id <= n) ans1.push_back(id);
		else ans2.push_back(id - n);	
	}
}
void solve(){
	cin >> n >> m;
	p[0] = 1;
	for(int i = 1; i <= m; i++)
	    p[i] = p[i-1] * B;
	for(int i = 1; i <= 2 * n; i++){
		cin >> a[i];
		ull x = 0;
		for(int j = 0; j < m; j++){
			x = x * B + (a[i][j] - 'a' + 1);
			hs[i].push_back(x);
		}
	}
	bool flag = 0;
	for(int i = 0; i < m; i++)
	    if(work(i)){
	    	flag = 1;
	    	break;
		}	
	if(flag){
		dfs(1);
		for(auto id : ans1) cout << id << ' ';
		cout << '\n';
		for(auto id : ans2) cout << id << ' ';
		cout << '\n';
		ans1.clear(), ans2.clear();
	}
	else cout << "-1\n";
	for(int i = 1; i <= 2 * n; i++)
	    hs[i].clear();			    
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	int t;
	cin >> t;
	while(t--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 23ms
memory: 160248kb

input:

2
3 3
abc
ghi
def
bcd
efg
hia
1 3
abc
def

output:

2 3 1 
3 2 1 
-1

result:

wrong answer not cyclic isomorphism (test case 1)