QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#241312 | #7686. The Phantom Menace | ucup-team1134# | WA | 590ms | 52468kb | C++17 | 4.8kb | 2023-11-06 02:04:20 | 2023-11-06 02:04:20 |
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-09 15:33:42]
- hack成功,自动添加数据
- (//qoj.ac/hack/445)
- [2023-11-06 02:04:20]
- 提交
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod1=1000000009,mod2=1000099999,MAX=2000005,INF=1<<30;
struct Rollinghash{
string S;
int n;
int base1;
int base2;
vector<ll> h1,h2,ru1,ru2;
void make(string &T,int ba1,int ba2){
S=T;
n=S.size();
h1.assign(n+1,0);
h2.assign(n+1,0);
ru1.assign(n+1,0);
ru2.assign(n+1,0);
base1=ba1;
base2=ba2;
ru1[0]=1;
ru2[0]=1;
for(int i=1;i<=n;i++){
h1[i]=h1[i-1]*base1+ll(S[i-1]-'A');
h1[i]%=mod1;
h2[i]=h2[i-1]*base2+ll(S[i-1]-'A');
h2[i]%=mod2;
ru1[i]=ru1[i-1]*base1%mod1;
ru2[i]=ru2[i-1]*base2%mod2;
}
}
pair<ll,ll> ha(int l,int r){
pair<ll,ll> res;
res.fi=(h1[r]-h1[l]*ru1[r-l]%mod1+mod1)%mod1;
res.se=(h2[r]-h2[l]*ru2[r-l]%mod2+mod2)%mod2;
return res;
}//開区間
};
vector<pair<int,int>> G[MAX];
bool visited[2*MAX];
void DFS(int u, vector<int> &trail) {
while(!G[u].empty()) {
int v=G[u].back().fi,id=G[u].back().se;
G[u].pop_back();
if(visited[id]) continue;
visited[id]=1;
trail.push_back(id);
DFS(v,trail);
}
//trail.push_back(u);
}
int main(){
std::ifstream in("text.txt");
std::cin.rdbuf(in.rdbuf());
cin.tie(0);
ios::sync_with_stdio(false);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll ha1=rng()%mod1;
ll ha2=rng()%mod2;
int Q;cin>>Q;
while(Q--){
int N,M;cin>>N>>M;
vector<string> S(N),T(N);
for(int i=0;i<N;i++) cin>>S[i];
for(int i=0;i<N;i++) cin>>T[i];
{
vector<pair<string,int>> A(N),B(N);
for(int i=0;i<N;i++) A[i]=mp(S[i],i);
for(int i=0;i<N;i++) B[i]=mp(T[i],i);
sort(all(A));
sort(all(B));
bool ch=true;
for(int i=0;i<N;i++) ch&=(A[i].fi==B[i].fi);
if(ch){
for(int i=0;i<N;i++) cout<<A[i].se+1<<" ";
cout<<endl;
for(int i=0;i<N;i++) cout<<B[i].se+1<<" ";
cout<<endl;
continue;
}
}
vector<Rollinghash> rol(2*N);
for(int i=0;i<N;i++){
rol[i].make(S[i],ha1,ha2);
}
for(int i=0;i<N;i++){
rol[N+i].make(T[i],ha1,ha2);
}
vector<int> ans1,ans2;
for(int al=1;al<M;al++){
vector<pair<pair<ll,ll>,int>> use;
for(int i=0;i<N;i++){
use.push_back(mp(rol[i].ha(0,al),0));
use.push_back(mp(rol[i].ha(al,M),1));
}
for(int i=0;i<N;i++){
use.push_back(mp(rol[N+i].ha(0,M-al),1));
use.push_back(mp(rol[N+i].ha(M-al,M),0));
}
sort(all(use));
use.erase(unique(all(use)),use.end());
int K=si(use);
auto f=[&](pair<pair<ll,ll>,int> x){
return (int)(lower_bound(all(use),x)-use.begin());
};
for(int i=0;i<N;i++){
int s=f(mp(rol[i].ha(0,al),0)),t=f(mp(rol[i].ha(al,M),1));
G[s].push_back(mp(t,i));
}
for(int i=0;i<N;i++){
int s=f(mp(rol[N+i].ha(0,M-al),1)),t=f(mp(rol[N+i].ha(M-al,M),0));
G[s].push_back(mp(t,N+i));
}
vector<int> tr;
DFS(0,tr);
for(int i=0;i<K;i++){
G[i].clear();
visited[2*i]=visited[2*i+1]=false;
}
if(si(tr)==N+N){
for(int i=0;i<2*N;i++){
if(i%2==0) ans1.push_back(tr[i]);
else ans2.push_back(tr[i]);
}
break;
}
}
if(si(ans1)==0) cout<<-1<<"\n";
else{
if(ans1[0]>=N) swap(ans1,ans2);
for(int a:ans1) cout<<a+1<<" ";
cout<<endl;
for(int a:ans2) cout<<a+1-N<<" ";
cout<<endl;
}
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 52468kb
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: 590ms
memory: 50988kb
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: 427ms
memory: 50676kb
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 34)