QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#625447#7686. The Phantom Menacelmx111WA 777ms5740kbC++203.4kb2024-10-09 19:22:382024-10-09 19:22:38

Judging History

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

  • [2024-10-09 19:22:38]
  • 评测
  • 测评结果:WA
  • 用时:777ms
  • 内存:5740kb
  • [2024-10-09 19:22:38]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long 
#define endl '\n'
using namespace std;
const int maxn = 1000010;
int n, m, u, v, del[maxn];
int du[maxn][2];
stack<int>st;
vector<pair<int,int>>z[maxn];
void dfs(int now, int id) {
	for (int i = del[now]; i < z[now].size(); i = del[now]) {
		del[now] = i + 1;
		dfs(z[now][i].first, z[now][i].second);
	}
	st.push(id);
}
int ans[maxn];
bool check() {
	for (int i = 1; i <= n; i++) {
		sort(z[i].begin(), z[i].end());
	}
	int S = 1, cnt[2] = { 0,0 };
	bool flag = 1;
	for (int i = 1; i <= n; i++) {
		if (du[i][1] != du[i][0]) {
			flag = 0;
			if (du[i][1] - du[i][0] == 1) {
				cnt[1]++;
				S = i;
			}
			else {
				if (du[i][0] - du[i][1] == 1) {
					cnt[0]++;
				}
				else {
					return 0;
				}
			}
		}
	}
	if ((!flag) && !(cnt[0] == cnt[1] && cnt[0] == 1)) {
		return 0;
	}
	dfs(S, 1);
	int c = 0;
	while (!st.empty()) {
		ans[c++] = st.top();
		st.pop();
	}
	return 1;
}
void solve() {
	int n, m;
	cin >> n >> m;
	vector<string>s1(n + 2);
	vector<string>s2(n + 2);
	for (int i = 1; i <= n; i++) {
		cin >> s1[i];
		s1[i] = '!' + s1[i];
	}
	for (int i = 1; i <= n; i++) {
		cin >> s2[i];
		s2[i] = '!' + s2[i];
	}
	map<string, int>zzz;
	vector<int>res;
	int flag = 0;
	for (int i = 1; i <= n; i++) {
		zzz[s1[i]] = i;
	}
	for (int i = 1; i <= n; i++) {
		if (zzz.count(s2[i])) {
			res.push_back(zzz[s2[i]]);
		}
		else {
			flag = 1;
			break;
		}
	}
	if (flag == 0) {
		for (int i = 0; i < n; i++) {
			cout << res[i] << ' ';
		}
		cout << endl;
		for (int i = 1; i <= n; i++) {
			cout << i << ' ';
		}
		cout << endl;
		return;
	}

	unordered_map<string, int>z1;
	unordered_map<string, int>z2;
	int tot1 = 0, tot2 = 0;
	for (int i = 1; i < m; i++) {
		for (int i = 1; i <= min(100005ll, (tot1 + tot2) * 4); i++) {
			z[i].clear();
		}
		z1.clear();
		z2.clear();
		tot1 = 0, tot2 = 0;
		for (int j = 1; j <= n; j++) {
			string pre = s1[j].substr(1, i);
			string las = s1[j].substr(i + 1, m - i);
			int a1, a2;
			if (z1.count(pre)) {
				a1 = z1[pre];
			}
			else {
				z1[pre] = ++tot1;
				a1 = tot1;
			}
			if (z2.count(las)) {
				a2 = z2[las];
			}
			else {
				z2[las] = ++tot2;
				a2 = tot2;
			}
			z[a1].push_back({ a2 + n * 2,j });
		}
		for (int j = 1; j <= n; j++) {
			string pre = s2[j].substr(1, m - i);
			string las = s2[j].substr(m - i + 1, i);
			int a1, a2;
			if (z2.count(pre)) {
				a1 = z2[pre];
			}
			else {
				z2[pre] = ++tot1;
				a1 = tot1;
			}
			if (z1.count(las)) {
				a2 = z1[las];
			}
			else {
				z1[las] = ++tot2;
				a2 = tot2;
			}
			z[a1 + n * 2].push_back({ a2,j + n });
		}
		check();
		if (ans[n * 2] != 0) {
			vector<int> p, q;
			for (int i = 1; i <= n * 2;i++) {
				int x = ans[i];
				if (x <= n) {
					p.push_back(x);
				}
				else {
					q.push_back(x - n);
				}
			}
			for (int i = 0; i < n; i++) {
				cout << p[i] << ' ';
			}
			cout << endl;
			for (int i = 0; i < n; i++) {
				cout << q[i] << ' ';
			}
			for (int i = 0; i <= n * 2 + 1; i++) {
				ans[i] = 0;
			}
			for (int i = 1; i <= min(100005ll, (tot1 + tot2) * 4); i++) {
				z[i].clear();
			}
			cout << endl;
			return;
		}
		for (int i = 0; i <= n*2+1; i++) {
			ans[i] = 0;
		}
	}
	cout << -1 << endl;
}
signed main() {
	int t;
	cin >> t;
	while (t--) {
		solve();
	}
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 5612kb

input:

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

output:

1 3 2 
1 2 3 
-1

result:

ok 2 cases (2 test cases)

Test #2:

score: 0
Accepted
time: 777ms
memory: 5704kb

input:

1000000
1 1
b
b
1 1
a
b
1 1
b
a
1 1
a
a
1 1
b
b
1 1
a
b
1 1
b
a
1 1
a
a
1 1
b
b
1 1
a
b
1 1
b
a
1 1
a
a
1 1
b
b
1 1
a
b
1 1
b
a
1 1
a
a
1 1
b
b
1 1
a
b
1 1
b
a
1 1
a
a
1 1
b
b
1 1
a
b
1 1
b
a
1 1
a
a
1 1
b
b
1 1
a
b
1 1
b
a
1 1
a
a
1 1
b
b
1 1
a
b
1 1
b
a
1 1
a
a
1 1
b
b
1 1
a
b
1 1
b
a
1 1
a
a
1 1
...

output:

1 
1 
-1
-1
1 
1 
1 
1 
-1
-1
1 
1 
1 
1 
-1
-1
1 
1 
1 
1 
-1
-1
1 
1 
1 
1 
-1
-1
1 
1 
1 
1 
-1
-1
1 
1 
1 
1 
-1
-1
1 
1 
1 
1 
-1
-1
1 
1 
1 
1 
-1
-1
1 
1 
1 
1 
-1
-1
1 
1 
1 
1 
-1
-1
1 
1 
1 
1 
-1
-1
1 
1 
1 
1 
-1
-1
1 
1 
1 
1 
-1
-1
1 
1 
1 
1 
-1
-1
1 
1 
1 
1 
-1
-1
1 
1 
1 
1 
-1
-1
...

result:

ok 1000000 cases (1000000 test cases)

Test #3:

score: -100
Wrong Answer
time: 490ms
memory: 5740kb

input:

500000
1 2
dd
ba
1 2
cd
ba
1 2
bd
ba
1 2
ad
ba
1 2
dc
ba
1 2
cc
ba
1 2
bc
ba
1 2
ac
ba
1 2
db
ba
1 2
cb
ba
1 2
bb
ba
1 2
ab
ba
1 2
da
ba
1 2
ca
ba
1 2
ba
ba
1 2
aa
ba
1 2
dd
aa
1 2
cd
aa
1 2
bd
aa
1 2
ad
aa
1 2
dc
aa
1 2
cc
aa
1 2
bc
aa
1 2
ac
aa
1 2
db
aa
1 2
cb
aa
1 2
bb
aa
1 2
ab
aa
1 2
da
aa
1 2...

output:

-1
-1
-1
-1
-1
-1
-1
-1
1 
1 
-1
-1
-1
-1
-1
1 
1 
-1
-1
-1
-1
1 
1 
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1 
1 
1 
1 
1 
1 
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1 
1 
-1
-1
-1
-1
1 
1 
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1 
1 
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1 
1 
-1
-1
-1
-1
-1
-1
...

result:

wrong answer not cyclic isomorphism (test case 9)