QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#758512#5311. Master of BothzaqmjuWA 0ms3624kbC++201.2kb2024-11-17 18:39:032024-11-17 18:39:03

Judging History

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

  • [2024-11-17 18:39:03]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3624kb
  • [2024-11-17 18:39:03]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int N = 1e6 + 10;
int cnt[50][50];
int son[N][50], sum[N][50];
string s;
void solve() {
	int n, q;
	cin >> n >> q;
	// vector<vector<int>> cnt(30, vector<int> (30));
	// vector<vector<int>> son(N,vector<int> (30));
	// auto sum = son;
	int idx = 0;
	auto insert = [&]() {
		int p = 0;
		for(int i = 0; i < (int)s.size(); i++) {
			int u = s[i] - 'a' + 1;
			if(!son[p][u]) son[p][u] = ++idx;
			for(int j = 0; j < 27; j++) {
				cnt[j + 1][u + 1] += sum[p][j];
			}
			sum[p][u]++;
			p = son[p][u];
		}
	};
	// vector<string> s(n + 1);
	for(int i = 1; i <= n; i++) {
		// cin >> s[i];
		s[i] += ('a' - 1);
		insert();
	}
	while(q--) {
		string ss;
		cin >> ss;
		ss = char('a' - 1) + ss;
		vector<int> now(30);
		for(int i = 0; i < 27; i++) {
			now[ss[i] - 'a' + 1] = i;
		}
		int ans = 0;
		for(int i = 0; i < 27; i++) {
			for(int j = 0; j < 27; j++) {
				if(now[i] > now[j]) {
					ans += cnt[i + 1][j + 1];
				}
			}
		}
		cout << ans << endl;
	}
}

#undef int 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t = 1;
	// cin >> t;
	while(t--) {
		solve();
	}
	return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3624kb

input:

5 3
aac
oiputata
aaa
suikabudada
aba
abcdefghijklmnopqrstuvwxyz
qwertyuiopasdfghjklzxcvbnm
aquickbrownfxjmpsvethlzydg

output:

0
0
0

result:

wrong answer 1st numbers differ - expected: '4', found: '0'