QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#561234#7686. The Phantom MenacelyxeasonTL 386ms203564kbC++144.1kb2024-09-12 21:24:322024-09-12 21:24:35

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-12 21:24:35]
  • 评测
  • 测评结果:TL
  • 用时:386ms
  • 内存:203564kb
  • [2024-09-12 21:24:32]
  • 提交

answer



#include <map>
#include <ctime>
#include <cstdio>
#include <vector>
#include <cstdlib>
#define ll long long

using namespace std;

ll P;
const ll D = 131;
int T;
int N;
int M;
vector<ll> SA1[1000009];
vector<ll> SB1[1000009];
vector<int> idA1[1000009];
vector<int> idA2[1000009];
vector<int> idB1[1000009];
vector<int> idB2[1000009];
char s[1000009];
struct Node {
    int v;
    int id;
};
ll PD[1000009];
vector<Node> E[2000009];
int deg2[2000009];
int idx;
map<ll, int> SA;
map<ll, int> SB;
int ba[2000009];
int n;
bool va[2000009];
int res[2000009];
int nn;
int resa[1000009];
int resb[1000009];
int a;
int b;

void Dfs (int x) {
    Node v;
    while (!E[x].empty()) {
        v = E[x].back(), E[x].pop_back();
        Dfs(v.v);
        res[++nn] = v.id;
    }
}

int main () {
    ll s2;
    bool f;
    srand(time(0));
    P = (double)(rand()) / (double)(RAND_MAX) * 1e9 + 1e9;
    do {
        P++;
        f = true;
        for (int i = 2; i * i <= P; i++)
            if (!(P % i)) {
                f = false;
                break;
            }
    } while (!f);
    PD[0] = 1;
    for (int i = 1; i <= 1000000; i++) PD[i] = (PD[i - 1] * D) % P;
    scanf("%d", &T);
    while (T--) {
        scanf("%d%d", &N, &M);
        SA.clear(), SB.clear(), idx = 0;
        for (int i = 1; i <= N; i++) {
            scanf("%s", s + 1);
            idA1[i].clear(), idA2[i].clear();
            SA1[i].clear();
            s2 = 0;
            idA1[i].push_back(0), idA2[i].push_back(0);
            SA1[i].push_back(0);
            for (int j = 1; j <= M; j++) {
                s2 = (s2 + PD[j - 1] * (ll)(s[M - j + 1] - 'a' + 1)) % P;
                SA1[i].push_back((SA1[i].back() * D + (ll)(s[j] - 'a' + 1)) % P);
                a = SA[s2];
                if (!a) a = SA[s2] = ++idx;
                idA2[i].push_back(a);
            }
        }
        for (int i = 1; i <= N; i++) {
            scanf("%s", s + 1);
            idB1[i].clear(), idB2[i].clear();
            SB1[i].clear();
            s2 = 0;
            idB1[i].push_back(0), idB2[i].push_back(0);
            SB1[i].push_back(0);
            for (int j = 1; j <= M; j++) {
                s2 = (s2 + PD[j - 1] * (ll)(s[M - j + 1] - 'a' + 1)) % P;
                SB1[i].push_back((SB1[i].back() * D + (ll)(s[j] - 'a' + 1)) % P);
                a = SB[s2];
                if (!a) a = SB[s2] = ++idx;
                idB2[i].push_back(a);
            }
        }
        for (int i = 1; i <= N; i++)
            for (int j = 1; j <= M; j++) {
                idA1[i].push_back(SB[SA1[i][j]]);
                idB1[i].push_back(SA[SB1[i][j]]);
            }
        f = false;
        for (int i = 1; i <= M; i++) {
            for (int j = 1; j <= n; j++) E[ba[j]].clear(), va[ba[j]] = deg2[ba[j]] = 0;
            n = 0;
            for (int j = 1; j <= N; j++) {
                a = idA1[j][i], b = idA2[j][M - i];
                if (!va[a]) va[a] = true, ba[++n] = a;
                if (!va[b]) va[b] = true, ba[++n] = b;
                E[a].push_back({b, j});
                deg2[b]++;
                a = idB1[j][M - i], b = idB2[j][i];
                if (!va[a]) va[a] = true, ba[++n] = a;
                if (!va[b]) va[b] = true, ba[++n] = b;
                E[a].push_back({b, j + N});
                deg2[b]++;
            }
            f = true;
            for (int j = 1; j <= n; j++)
                if (deg2[ba[j]] != E[ba[j]].size()) {
                    f = false;
                    break;
                }
            if (!f) continue;
            nn = 0;
            Dfs(ba[1]);
            if (nn < 2 * N) {
                f = false;
                continue;
            }
            a = b = 0;
            for (int j = nn; j; j--)
                if (res[j] <= N) resa[++a] = res[j];
                else resb[++b] = res[j] - N;
            for (int j = 1; j <= N; j++) printf("%d ", resa[j]);
            puts("");
            for (int j = 1; j <= N; j++) printf("%d ", resb[j]);
            puts("");
            break;
        }
        if (!f) puts("-1");
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 35ms
memory: 199316kb

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: 383ms
memory: 199340kb

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: 0
Accepted
time: 276ms
memory: 199320kb

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:

ok 500000 cases (500000 test cases)

Test #4:

score: 0
Accepted
time: 304ms
memory: 199344kb

input:

500000
2 1
d
d
b
a
2 1
c
d
b
a
2 1
b
d
b
a
2 1
a
d
b
a
2 1
d
c
b
a
2 1
c
c
b
a
2 1
b
c
b
a
2 1
a
c
b
a
2 1
d
b
b
a
2 1
c
b
b
a
2 1
b
b
b
a
2 1
a
b
b
a
2 1
d
a
b
a
2 1
c
a
b
a
2 1
b
a
b
a
2 1
a
a
b
a
2 1
d
d
a
a
2 1
c
d
a
a
2 1
b
d
a
a
2 1
a
d
a
a
2 1
d
c
a
a
2 1
c
c
a
a
2 1
b
c
a
a
2 1
a
c
a
a
2 1
d...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1 2 
1 2 
-1
-1
1 2 
2 1 
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
2 1 
2 1 
2 1 
2 1 
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1 2 
2 1 
-1
-1
1 2 
1 2 
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1 2 
2 1 
-1
-1
-1
-1
-1
1 2 
1 2 
-1
-1
-1
-1
-1
-1
-1
-1
-...

result:

ok 500000 cases (500000 test cases)

Test #5:

score: 0
Accepted
time: 234ms
memory: 199388kb

input:

333333
1 3
cbb
bfa
1 3
bbb
bfa
1 3
abb
bfa
1 3
fab
bfa
1 3
eab
bfa
1 3
dab
bfa
1 3
cab
bfa
1 3
bab
bfa
1 3
aab
bfa
1 3
ffa
bfa
1 3
efa
bfa
1 3
dfa
bfa
1 3
cfa
bfa
1 3
bfa
bfa
1 3
afa
bfa
1 3
fea
bfa
1 3
eea
bfa
1 3
dea
bfa
1 3
cea
bfa
1 3
bea
bfa
1 3
aea
bfa
1 3
fda
bfa
1 3
eda
bfa
1 3
dda
bfa
1 3
c...

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 333333 cases (333333 test cases)

Test #6:

score: 0
Accepted
time: 258ms
memory: 199380kb

input:

333333
3 1
c
b
b
b
f
a
3 1
b
b
b
b
f
a
3 1
a
b
b
b
f
a
3 1
f
a
b
b
f
a
3 1
e
a
b
b
f
a
3 1
d
a
b
b
f
a
3 1
c
a
b
b
f
a
3 1
b
a
b
b
f
a
3 1
a
a
b
b
f
a
3 1
f
f
a
b
f
a
3 1
e
f
a
b
f
a
3 1
d
f
a
b
f
a
3 1
c
f
a
b
f
a
3 1
b
f
a
b
f
a
3 1
a
f
a
b
f
a
3 1
f
e
a
b
f
a
3 1
e
e
a
b
f
a
3 1
d
e
a
b
f
a
3 1
c...

output:

-1
-1
-1
1 2 3 
3 1 2 
-1
-1
-1
-1
-1
-1
-1
-1
-1
1 3 2 
3 2 1 
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1 3 2 
3 1 2 
-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
2 1 3 
3 2 1 
-1
-1
-1
-1
-...

result:

ok 333333 cases (333333 test cases)

Test #7:

score: 0
Accepted
time: 231ms
memory: 199380kb

input:

250000
1 4
hbca
fhaa
1 4
gbca
fhaa
1 4
fbca
fhaa
1 4
ebca
fhaa
1 4
dbca
fhaa
1 4
cbca
fhaa
1 4
bbca
fhaa
1 4
abca
fhaa
1 4
haca
fhaa
1 4
gaca
fhaa
1 4
faca
fhaa
1 4
eaca
fhaa
1 4
daca
fhaa
1 4
caca
fhaa
1 4
baca
fhaa
1 4
aaca
fhaa
1 4
hhba
fhaa
1 4
ghba
fhaa
1 4
fhba
fhaa
1 4
ehba
fhaa
1 4
dhba
fhaa...

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 250000 cases (250000 test cases)

Test #8:

score: 0
Accepted
time: 239ms
memory: 199336kb

input:

250000
4 1
h
b
c
a
f
h
a
a
4 1
g
b
c
a
f
h
a
a
4 1
f
b
c
a
f
h
a
a
4 1
e
b
c
a
f
h
a
a
4 1
d
b
c
a
f
h
a
a
4 1
c
b
c
a
f
h
a
a
4 1
b
b
c
a
f
h
a
a
4 1
a
b
c
a
f
h
a
a
4 1
h
a
c
a
f
h
a
a
4 1
g
a
c
a
f
h
a
a
4 1
f
a
c
a
f
h
a
a
4 1
e
a
c
a
f
h
a
a
4 1
d
a
c
a
f
h
a
a
4 1
c
a
c
a
f
h
a
a
4 1
b
a
c
a
f...

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 4 3 2 
4 3 2 1 
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 250000 cases (250000 test cases)

Test #9:

score: 0
Accepted
time: 216ms
memory: 199328kb

input:

200000
1 5
jjjjj
baaaa
1 5
ijjjj
baaaa
1 5
hjjjj
baaaa
1 5
gjjjj
baaaa
1 5
fjjjj
baaaa
1 5
ejjjj
baaaa
1 5
djjjj
baaaa
1 5
cjjjj
baaaa
1 5
bjjjj
baaaa
1 5
ajjjj
baaaa
1 5
jijjj
baaaa
1 5
iijjj
baaaa
1 5
hijjj
baaaa
1 5
gijjj
baaaa
1 5
fijjj
baaaa
1 5
eijjj
baaaa
1 5
dijjj
baaaa
1 5
cijjj
baaaa
1 5
b...

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 200000 cases (200000 test cases)

Test #10:

score: 0
Accepted
time: 204ms
memory: 203428kb

input:

200000
5 1
j
j
j
j
j
b
a
a
a
a
5 1
i
j
j
j
j
b
a
a
a
a
5 1
h
j
j
j
j
b
a
a
a
a
5 1
g
j
j
j
j
b
a
a
a
a
5 1
f
j
j
j
j
b
a
a
a
a
5 1
e
j
j
j
j
b
a
a
a
a
5 1
d
j
j
j
j
b
a
a
a
a
5 1
c
j
j
j
j
b
a
a
a
a
5 1
b
j
j
j
j
b
a
a
a
a
5 1
a
j
j
j
j
b
a
a
a
a
5 1
j
i
j
j
j
b
a
a
a
a
5 1
i
i
j
j
j
b
a
a
a
a
5 1
h...

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 200000 cases (200000 test cases)

Test #11:

score: 0
Accepted
time: 234ms
memory: 199208kb

input:

250000
2 2
hb
ca
fh
aa
2 2
gb
ca
fh
aa
2 2
fb
ca
fh
aa
2 2
eb
ca
fh
aa
2 2
db
ca
fh
aa
2 2
cb
ca
fh
aa
2 2
bb
ca
fh
aa
2 2
ab
ca
fh
aa
2 2
ha
ca
fh
aa
2 2
ga
ca
fh
aa
2 2
fa
ca
fh
aa
2 2
ea
ca
fh
aa
2 2
da
ca
fh
aa
2 2
ca
ca
fh
aa
2 2
ba
ca
fh
aa
2 2
aa
ca
fh
aa
2 2
hh
ba
fh
aa
2 2
gh
ba
fh
aa
2 2
f...

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 2 
2 1 
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1...

result:

ok 250000 cases (250000 test cases)

Test #12:

score: 0
Accepted
time: 183ms
memory: 199248kb

input:

166666
2 3
jef
aia
aaa
aaa
2 3
ief
aia
aaa
aaa
2 3
hef
aia
aaa
aaa
2 3
gef
aia
aaa
aaa
2 3
fef
aia
aaa
aaa
2 3
eef
aia
aaa
aaa
2 3
def
aia
aaa
aaa
2 3
cef
aia
aaa
aaa
2 3
bef
aia
aaa
aaa
2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1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 166666 cases (166666 test cases)

Test #14:

score: 0
Accepted
time: 156ms
memory: 203404kb

input:

125000
2 4
heio
baaa
aaaa
aaaa
2 4
geio
baaa
aaaa
aaaa
2 4
feio
baaa
aaaa
aaaa
2 4
eeio
baaa
aaaa
aaaa
2 4
deio
baaa
aaaa
aaaa
2 4
ceio
baaa
aaaa
aaaa
2 4
beio
baaa
aaaa
aaaa
2 4
aeio
baaa
aaaa
aaaa
2 4
pdio
baaa
aaaa
aaaa
2 4
odio
baaa
aaaa
aaaa
2 4
ndio
baaa
aaaa
aaaa
2 4
mdio
baaa
aaaa
aaaa
2 4
l...

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 125000 cases (125000 test cases)

Test #15:

score: 0
Accepted
time: 156ms
memory: 199344kb

input:

125000
4 2
he
io
ba
aa
aa
aa
aa
aa
4 2
ge
io
ba
aa
aa
aa
aa
aa
4 2
fe
io
ba
aa
aa
aa
aa
aa
4 2
ee
io
ba
aa
aa
aa
aa
aa
4 2
de
io
ba
aa
aa
aa
aa
aa
4 2
ce
io
ba
aa
aa
aa
aa
aa
4 2
be
io
ba
aa
aa
aa
aa
aa
4 2
ae
io
ba
aa
aa
aa
aa
aa
4 2
pd
io
ba
aa
aa
aa
aa
aa
4 2
od
io
ba
aa
aa
aa
aa
aa
4 2
nd
io
ba
...

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 125000 cases (125000 test cases)

Test #16:

score: 0
Accepted
time: 148ms
memory: 199388kb

input:

100000
2 5
ttjma
aaaaa
aaaaa
aaaaa
2 5
stjma
aaaaa
aaaaa
aaaaa
2 5
rtjma
aaaaa
aaaaa
aaaaa
2 5
qtjma
aaaaa
aaaaa
aaaaa
2 5
ptjma
aaaaa
aaaaa
aaaaa
2 5
otjma
aaaaa
aaaaa
aaaaa
2 5
ntjma
aaaaa
aaaaa
aaaaa
2 5
mtjma
aaaaa
aaaaa
aaaaa
2 5
ltjma
aaaaa
aaaaa
aaaaa
2 5
ktjma
aaaaa
aaaaa
aaaaa
2 5
jtjma
aaa...

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 100000 cases (100000 test cases)

Test #17:

score: 0
Accepted
time: 135ms
memory: 203348kb

input:

100000
5 2
tt
jm
aa
aa
aa
aa
aa
aa
aa
aa
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-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 111111 cases (111111 test cases)

Test #19:

score: 0
Accepted
time: 125ms
memory: 199264kb

input:

83333
3 4
eqag
aaaa
aaaa
aaaa
aaaa
aaaa
3 4
dqag
aaaa
aaaa
aaaa
aaaa
aaaa
3 4
cqag
aaaa
aaaa
aaaa
aaaa
aaaa
3 4
bqag
aaaa
aaaa
aaaa
aaaa
aaaa
3 4
aqag
aaaa
aaaa
aaaa
aaaa
aaaa
3 4
xpag
aaaa
aaaa
aaaa
aaaa
aaaa
3 4
wpag
aaaa
aaaa
aaaa
aaaa
aaaa
3 4
vpag
aaaa
aaaa
aaaa
aaaa
aaaa
3 4
upag
aaaa
aaaa
aaa...

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 83333 cases (83333 test cases)

Test #20:

score: 0
Accepted
time: 124ms
memory: 199344kb

input:

83333
4 3
eqa
gaa
aaa
aaa
aaa
aaa
aaa
aaa
4 3
dqa
gaa
aaa
aaa
aaa
aaa
aaa
aaa
4 3
cqa
gaa
aaa
aaa
aaa
aaa
aaa
aaa
4 3
bqa
gaa
aaa
aaa
a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-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 66666 cases (66666 test cases)

Test #22:

score: 0
Accepted
time: 124ms
memory: 199328kb

input:

66666
5 3
bqu
daa
aaa
aaa
aaa
aaa
aaa
aaa
aaa
aaa
5 3
aqu
daa
aaa
aaa
aaa
aaa
aaa
aaa
aaa
aaa
5 3
zpu
daa
aaa
aaa
aaa
aaa
aaa
aaa
aaa
aaa
5 3
ypu
daa
aaa
aaa
aaa
aaa
aaa
aaa
aaa
aaa
5 3
xpu
daa
aaa
aaa
aaa
aaa
aaa
aaa
aaa
aaa
5 3
wpu
daa
aaa
aaa
aaa
aaa
aaa
aaa
aaa
aaa
5 3
vpu
daa
aaa
aaa
aaa
aaa
aa...

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 66666 cases (66666 test cases)

Test #23:

score: 0
Accepted
time: 104ms
memory: 199268kb

input:

20833
6 8
gvebaaaa
aaaaaaaa
aaaaaaaa
aaaaaaaa
aaaaaaaa
aaaaaaaa
aaaaaaaa
aaaaaaaa
aaaaaaaa
aaaaaaaa
aaaaaaaa
aaaaaaaa
6 8
fvebaaaa
aaaaaaaa
aaaaaaaa
aaaaaaaa
aaaaaaaa
aaaaaaaa
aaaaaaaa
aaaaaaaa
aaaaaaaa
aaaaaaaa
aaaaaaaa
aaaaaa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1
-1
-1
-1
...

result:

ok 15873 cases (15873 test cases)

Test #25:

score: 0
Accepted
time: 92ms
memory: 199756kb

input:

10000
10 10
puoaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
10 10
ouoaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaa...

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 10000 cases (10000 test cases)

Test #26:

score: 0
Accepted
time: 287ms
memory: 199340kb

input:

250000
2 2
od
ah
ha
do
2 2
il
ng
il
ng
2 2
cf
pf
pf
cf
2 2
wx
ll
wx
ll
2 2
fg
ge
ge
fg
2 2
dg
mj
dg
mj
2 2
rj
vw
wr
jv
2 2
er
pv
pv
er
2 2
kc
lb
cl
bk
2 2
dh
zc
hz
cd
2 2
qv
ce
eq
vc
2 2
lz
um
zu
ml
2 2
hw
xx
hw
xx
2 2
uk
un
ku
nu
2 2
sg
kx
gs
xk
2 2
ib
xw
ib
xw
2 2
ar
pd
pd
ar
2 2
ij
si
ii
js
2 2
p...

output:

-1
1 2 
2 1 
1 2 
1 2 
1 2 
2 1 
1 2 
1 2 
1 2 
2 1 
1 2 
2 1 
1 2 
1 2 
1 2 
1 2 
1 2 
1 2 
1 2 
2 1 
1 2 
1 2 
1 2 
2 1 
2 1 
2 1 
-1
1 2 
2 1 
1 2 
1 2 
1 2 
2 1 
1 2 
1 2 
1 2 
2 1 
-1
1 2 
1 2 
1 2 
1 2 
1 2 
1 2 
1 2 
2 1 
1 2 
2 1 
1 2 
1 2 
-1
1 2 
2 1 
1 2 
1 2 
1 2 
1 2 
2 1 
2 1 
1 2 
1 2...

result:

ok 250000 cases (250000 test cases)

Test #27:

score: 0
Accepted
time: 285ms
memory: 199252kb

input:

166666
2 3
aib
avi
aib
avi
2 3
btw
xjw
xjw
btw
2 3
dng
ouv
uvd
ngo
2 3
ctq
sve
sve
ctq
2 3
ott
obm
ott
obm
2 3
aly
tmx
aly
tmx
2 3
nhm
zar
arn
hmz
2 3
knr
qpa
nrq
pak
2 3
gsw
fyn
sng
ywf
2 3
qcy
rov
qcy
rov
2 3
nmj
tyx
tyx
nmj
2 3
dbu
pim
pim
dbu
2 3
afj
zwf
ffa
wjz
2 3
vgo
sky
gyv
kos
2 3
zru
bog
u...

output:

1 2 
2 1 
1 2 
1 2 
1 2 
2 1 
1 2 
1 2 
1 2 
2 1 
1 2 
2 1 
1 2 
2 1 
1 2 
1 2 
-1
1 2 
2 1 
1 2 
1 2 
1 2 
1 2 
-1
-1
-1
-1
1 2 
2 1 
-1
1 2 
1 2 
1 2 
1 2 
-1
1 2 
2 1 
1 2 
2 1 
1 2 
1 2 
1 2 
1 2 
1 2 
1 2 
1 2 
2 1 
1 2 
2 1 
1 2 
2 1 
-1
1 2 
1 2 
1 2 
2 1 
1 2 
2 1 
1 2 
2 1 
1 2 
1 2 
-1
1 2...

result:

ok 166666 cases (166666 test cases)

Test #28:

score: 0
Accepted
time: 318ms
memory: 203564kb

input:

166666
3 2
yx
pd
tl
dt
xy
lp
3 2
xb
pc
cr
xb
pc
cr
3 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5 4 3 2 1 8 
1 2 7 8 3 5 4 6 
8 6 5 4 3 2 1 7 
3 5 6 2 1 7 8 4 
8 7 6 5 4 2 1 3 
1 6 5 4 3 7 2 8 
8 7 6 5 3 2 1 4 
1 8 3 6 2 5 7 4 
8 7 6 5 4 3 1 2 
1 2 8 3 6 4 7 5 
8 7 6 5 4 3...

result:

ok 125000 cases (125000 test cases)

Test #30:

score: 0
Accepted
time: 282ms
memory: 203436kb

input:

100000
1 10
klhmhvkswy
wykjhmhvks
1 10
uqieigoabd
qieigoabdu
1 10
bunljqpvov
vbunljqivo
1 10
ytkmhxtntc
xtntcytkmh
1 10
lufmlhxbvz
ufmlcxbvzl
1 10
cuemsefukn
sefukncueq
1 10
oomyzzliuk
zzliukoomy
1 10
piekrxtsag
rxtsagpiek
1 10
pwhbveolnf
nfpwhbveol
1 10
wsyjzqnbtj
jzqnbojwsy
1 10
iqayiqecea
aiqaytq...

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 100000 cases (100000 test cases)

Test #31:

score: 0
Accepted
time: 386ms
memory: 199292kb

input:

28571
7 5
rpdbr
kijbw
qotha
wvxmn
frbey
tdjed
vqpoy
havot
bwfrb
edrpd
mnkij
eyqqp
oytdj
brwvx
7 5
pecul
iozuk
kxkfg
ivcha
erold
abatw
otvoe
otvoe
kxkfg
abatw
ivcha
pecul
erold
iozuk
7 5
qmwhz
odnhu
dkzle
roeec
xftep
axzal
kgusp
ecdgu
huxft
epqmw
lekkz
alroe
hzaxz
spodn
7 5
aefno
popfk
shavv
cvhdy
na...

output:

-1
1 2 5 4 6 3 7 
7 6 4 3 2 1 5 
-1
1 7 4 6 3 5 2 
5 4 6 1 7 2 3 
-1
1 3 2 6 4 5 7 
2 4 6 1 3 5 7 
1 6 3 2 4 5 7 
4 3 7 6 5 2 1 
-1
1 4 7 3 5 2 6 
6 5 4 3 2 1 7 
-1
-1
1 3 6 7 2 4 5 
3 2 7 1 5 4 6 
1 7 3 5 6 4 2 
7 1 5 3 6 2 4 
-1
1 3 7 5 2 4 6 
2 5 7 3 4 6 1 
1 7 4 3 6 2 5 
7 6 5 4 3 2 1 
1 2 6 5 3...

result:

ok 28571 cases (28571 test cases)

Test #32:

score: -100
Time Limit Exceeded

input:

1
1000 1000
plxpgukngtaywjrcxufvdwswaozxzeeduaeqslxuzcevplzosuqsedbplkmzbpyogbndbzmyfeyqamtetcjmaosbaxcrmjanjeglavxlwksvvenehzgrovffaebdtpynzajedywisavqgjjtjnqktzltyfzbvrtsfmdkzsyougzyqcckjcjjtkewysagddaizqnnptunmfyqagnxrzjqpsoqzqptzvjnfilpbgmjbetcgnewclwqxmftpepudwufcmbqtpyxajfmabqyvlgqxzhgumauzxms...

output:


result: