QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#297055#7686. The Phantom MenaceyllcmWA 600ms140464kbC++142.7kb2024-01-03 21:54:122024-01-03 21:54:12

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-01-03 21:54:12]
  • 评测
  • 测评结果:WA
  • 用时:600ms
  • 内存:140464kb
  • [2024-01-03 21:54:12]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define db double
#define ull unsigned long long
#define pb push_back
#define pii pair<int, int>
#define FR first
#define SE second
using namespace std;
inline int read() {
  int x = 0; bool op = false;
  char c = getchar();
  while(!isdigit(c))op |= (c == '-'), c = getchar();
  while(isdigit(c))x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  return op ? -x : x;
}
const int N = 1e6 + 10;
const int B = 131;
int n, m;
int pw[N];
string s[N], t[N];
vector<ull> hss[N], hst[N];
int pre(int x, int y, int o) {
  if(o == 0)return hss[x][y];
  else return hst[x][y];
}
int suf(int x, int y, int o) {
  if(o == 0)return hss[x][m] - hss[x][y - 1] * pw[m - y + 1];
  else return hst[x][m] - hst[x][y - 1] * pw[m - y + 1];
}
int in[N], hd[N];
vector<pii> G[N];
vector<int> Eu;
void dfs(int u) {
  for(int i = hd[u]; i < G[u].size(); i = hd[u]) {
    pii e = G[u][i]; hd[u] = i + 1;
    dfs(e.FR); Eu.pb(e.SE);
  }
  return ;
}
bool chk(int p) {
  int tot = 0;
  unordered_map<ull, int> tb1, tb2;
  // printf("p:%d\n", p);
  for(int i = 1; i <= n; i++) {
    ull hp = pre(i, p, 0), hs = suf(i, p + 1, 0);
    if(!tb1.count(hp))tb1[hp] = ++tot, vector<pii>().swap(G[tot]), in[tot] = 0;
    if(!tb2.count(hs))tb2[hs] = ++tot, vector<pii>().swap(G[tot]), in[tot] = 0;
    // cout << tb1[hp] << ' ' << tb2[hs] << endl;
    G[tb1[hp]].pb({tb2[hs], i}); in[tb2[hs]]++;
  }
  for(int i = 1; i <= n; i++) {
    ull hp = pre(i, m - p, 1), hs = suf(i, m - p + 1, 1);
    if(!tb2.count(hp))tb2[hp] = ++tot, vector<pii>().swap(G[tot]), in[tot] = 0;
    if(!tb1.count(hs))tb1[hs] = ++tot, vector<pii>().swap(G[tot]), in[tot] = 0;
    // cout << tb2[hp] << ' ' << tb1[hs] << endl;
    G[tb2[hp]].pb({tb1[hs], i + n}); in[tb1[hs]]++;
  }
  for(int i = 1; i <= tot; i++)if(in[i] != G[i].size())return false;
  vector<int>().swap(Eu);
  dfs(1);
  if(Eu.size() != n * 2)return false;
  reverse(Eu.begin(), Eu.end());
  // for(int x : Eu)printf("%d ", x); putchar('\n');
  for(int x : Eu)if(x <= n)printf("%d ", x); putchar('\n');
  for(int x : Eu)if(x > n)printf("%d ", x - n); putchar('\n');
  return true;
}
void solve() {
  n = read(); m = read();
  for(int i = 1; i <= n; i++)cin >> s[i];
  for(int i = 1; i <= n; i++)cin >> t[i];
  for(int i = 1; i <= n; i++) {
    hss[i].resize(m + 1); hst[i].resize(m + 1);
    for(int j = 0; j < m; j++) {
      hss[i][j + 1] = hss[i][j] * B + s[i][j];
      hst[i][j + 1] = hst[i][j] * B + t[i][j];
    }
  }
  for(int i = 1; i <= m; i++)if(chk(i))return ;
  puts("-1");
  return ;
}
int main() {
  pw[0] = 1;
  for(int i = 1; i < N; i++)pw[i] = pw[i - 1] * B;
  int test = read();
  while(test--)solve();
  return 0;
}

详细

Test #1:

score: 100
Accepted
time: 16ms
memory: 140464kb

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: -100
Wrong Answer
time: 600ms
memory: 140352kb

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:

wrong answer Jury has the answer but participant has not (test case 4)