我拿自己代码尝试了7,8遍,UKE
然后我觉得有问题,跑去拿所有所有题解代码一交,全是UKE(大牛的考场AC代码也交了。
我就很无语了,样例过了,但全部UKE
然后我去vjudge上交,所有所有代码全是Time limit exceeded on test 2(我不知道语言选对没,语言选的是G ++14 6.4.0
尼玛,CF我谢谢你。
求大牛看我为这题交了20多遍的份上,救救我吧。(送上一枚来自蒟蒻关注)
代码:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 50000;
int a[maxn + 10][20], b[maxn + 10][20];
int n, m;
int ch[maxn << 5][20];
int tot = 0;
void Build(int x) {
for (int i = 1, u = 0; i <= m; i++) {
int c = b[x][i];
if (!ch[u][c]) ch[u][c] = ++tot;
u = ch[u][c];
}
return;
}
void Find(int x) {
int ans = 0;
for (int i = 1, u = 0; i <= m; i++) {
int c = a[x][i];
if (!ch[u][c]) break;
else ans++, u = ch[u][c];
}
cout << ans << " ";
return;
}
int main() {
int t;
cin >> t;
while (t--) {
tot = 0;
memset(ch, 0, sizeof ch);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 1, x; j <= m; j++) {
cin >> x;
a[i][j] = x;
b[i][x] = j;
}
Build(i);
}
for (int i = 1; i <= n; i++) Find(i);
cout << endl;
}
return 0;
}