QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#238173#7686. The Phantom Menaceucup-team346#WA 656ms318160kbC++143.7kb2023-11-04 15:58:292023-11-04 15:58:29

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)
  • [2023-11-04 15:58:29]
  • 评测
  • 测评结果:WA
  • 用时:656ms
  • 内存:318160kb
  • [2023-11-04 15:58:29]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2000005;
const int B = 131;
const int P0 = 1000000009;
const int P1 = 998244353;

int pwr(int x,int y,int MOD){
    int r = 1,t = x;
    while(y){
        if(y & 1) r = 1ll * r * t % MOD;
        t = 1ll * t * t % MOD;
        y >>= 1;
    }
    return r;
}

int invb0 = pwr(B,P0 - 2,P0);
int invb1 = pwr(B,P1 - 2,P1);

int n,m;
string s[N],t[N];
vector <pair <int,int> > hs[N],ht[N];

inline pair <int,int> getvals(int id,int l,int r){
    if(l > r) return make_pair(0,0);
    return make_pair(1ll * pwr(invb0,l - 1,P0) * (hs[id][r].first - hs[id][l - 1].first + P0) % P0 , 1ll * pwr(invb1,l - 1,P1) * (hs[id][r].second - hs[id][l - 1].second + P1) % P1);
}
inline pair <int,int> getvalt(int id,int l,int r){
    if(l > r) return make_pair(0,0);
    return make_pair(1ll * pwr(invb0,l - 1,P0) * (ht[id][r].first - ht[id][l - 1].first + P0) % P0 , 1ll * pwr(invb1,l - 1,P1) * (ht[id][r].second - ht[id][l - 1].second + P1) % P1);
}

vector <pair <int,int> > G[N << 1];
int cur[N << 1],vis[N << 2];
int stk[N << 2],tp;
void dfs(int u,int ind){
    // cout << u << ' ' << ind << ' ' << cur[u] << endl;
    for(int &i = cur[u];i < G[u].size();i ++){
        // cur[u] ++;
        if(vis[G[u][i].second + n]) continue;
        vis[G[u][i].second + n] = 1;
        dfs(G[u][i].first,G[u][i].second);
    }
    stk[++ tp] = ind;
}

bool solve(){
    cin >> n >> m;
    for(int i = 1;i <= n;i ++){
        cin >> s[i];
        s[i] = ' ' + s[i];
        hs[i].clear(); hs[i].push_back(make_pair(0,0));
        for(int j = 1;j <= m;j ++) hs[i].push_back(make_pair((hs[i].back().first + 1ll * pwr(B,j - 1,P0) * s[i][j]) % P0,(hs[i].back().second + 1ll * pwr(B,j - 1,P1) * s[i][j]) % P1));
    }
    for(int i = 1;i <= n;i ++){
        cin >> t[i];
        t[i] = ' ' + t[i];
        ht[i].clear(); ht[i].push_back(make_pair(0,0));
        for(int j = 1;j <= m;j ++) ht[i].push_back(make_pair((ht[i].back().first + 1ll * pwr(B,j - 1,P0) * t[i][j]) % P0,(ht[i].back().second + 1ll * pwr(B,j - 1,P1) * t[i][j]) % P1));
    }
    for(int l = 0;l < m;l ++){
        int tot = 0;
        map <pair <int,int>,int> mp[2];
        for(int i = 1;i <= n;i ++){
            pair <int,int> il = getvals(i,1,l),ir = getvals(i,l + 1,m); // l & m - l
            if(mp[0].find(il) == mp[0].end()) mp[0][il] = ++ tot;
            if(mp[1].find(ir) == mp[1].end()) mp[1][ir] = ++ tot;
            G[mp[0][il]].push_back(make_pair(mp[1][ir],i));
            // cout << il << ' ' << ir << ' ' << mp[0][il] << ' ' << mp[1][ir] << ' ' << i << endl;
        }
        for(int i = 1;i <= n;i ++){
            pair <int,int> il = getvalt(i,1,m - l),ir = getvalt(i,m - l + 1,m); // m - l & l
            if(mp[1].find(il) == mp[1].end()) mp[1][il] = ++ tot;
            if(mp[0].find(ir) == mp[0].end()) mp[0][ir] = ++ tot;
            G[mp[1][il]].push_back(make_pair(mp[0][ir],-i));
            // cout << il << ' ' << ir << ' ' << mp[1][il] << ' ' << mp[0][ir] << ' ' << -i << endl;
        }
        for(int i = 1;i <= tot;i ++) cur[i] = 0;
        tp = 0; dfs(1,0);
        for(int i = 1;i <= tot;i ++) G[i].clear();
        for(int i = 0;i <= n + n;i ++) vis[i] = 0;
        // for(int i = 1;i <= tp;i ++) cout << stk[i] << " \n"[i == tp];
        if(tp != n + n + 1) continue;
        for(int i = tp;i >= 1;i --) if(stk[i] > 0) cout << stk[i] << ' ';
        cout << '\n';
        for(int i = tp;i >= 1;i --) if(stk[i] < 0) cout << -stk[i] << ' ';
        cout << '\n';
        return 1;
    }
    return 0;
}

int main(){
    ios::sync_with_stdio(false);
    int TC;
    cin >> TC;
    while(TC --){
        if(!solve()) cout << -1 << '\n';
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 43ms
memory: 318160kb

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: 656ms
memory: 317672kb

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: 437ms
memory: 316840kb

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)