QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#246896 | #7686. The Phantom Menace | ucup-team052# | WA | 337ms | 175632kb | C++23 | 4.2kb | 2023-11-11 11:35:48 | 2023-11-11 11:35:49 |
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-11 11:35:48]
- 提交
answer
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
inline int read()
{
char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
if(nega==-1) return -ans;
return ans;
}
void print(vector<int> x){for(int i=0;i<(int)x.size();i++) printf("%d%c",x[i]," \n"[i==(int)x.size()-1]);}
#define N 1000005
string s[N],t[N];
int n,m;
struct Hash
{
int mod,B;
inline int add(int x,int y) {return x+y>=mod?x+y-mod:x+y;}
inline int add(int x,int y,int z) {return add(add(x,y),z);}
inline int sub(int x,int y) {return x-y<0?x-y+mod:x-y;}
inline int mul(int x,int y) {return 1LL*x*y%mod;}
inline int mul(int x,int y,int z) {return mul(mul(x,y),z);}
#define inc(x,y) x=add(x,y)
#define dec(x,y) x=sub(x,y)
int pw[N];
vector<int> hs[N],ht[N];
void init(int md,int b)
{
mod=md; B=b;
pw[0]=1; for(int i=1;i<=m+1;i++) pw[i]=mul(pw[i-1],B);
for(int i=1;i<=n;i++)
{
hs[i].resize(m+1);
ht[i].resize(m+1);
hs[i][0]=0;
ht[i][0]=0;
for(int j=1;j<=m;j++)
{
hs[i][j]=add(mul(hs[i][j-1],B),s[i][j-1]);
ht[i][j]=add(mul(ht[i][j-1],B),t[i][j-1]);
}
}
}
int shsh(int id,int l,int r) {return sub(hs[id][r],mul(hs[id][l-1],pw[r-l+1]));}
int thsh(int id,int l,int r) {return sub(ht[id][r],mul(ht[id][l-1],pw[r-l+1]));}
}h1,h2;
unordered_map<string,vector<int>> mp;
int chksame()
{
vector<int> ans;
for(int i=1;i<=n;i++) mp[s[i]].pb(i);
for(int i=1;i<=m;i++)
{
if(mp[t[i]].empty()) return 0;
ans.pb(mp[t[i]].back());
mp[t[i]].pop_back();
}
for(int i=1;i<=n;i++) printf("%d%c",i," \n"[i==n]);
print(ans);
return 1;
}
const int M=N*4;
struct N1
{
struct Edge{int u,v,nxt;};
Edge edge[M];
int fir[M],id[M],od[M],ss;
void clear()
{
ss=0;
for(int i=1;i<=n*4;i++) fir[i]=0,id[i]=0,od[i]=0;
}
void addedge(int u,int v)
{
// printf("%d %d\n",u,v);
edge[++ss]=(Edge){u,v,fir[u]}; fir[u]=ss;
id[u]++,od[v]++;
}
int vis[N],ans[N],dgr[N],cnt;
void dfs(int u)
{
for(int i=fir[u];i!=0;i=fir[u])
{
for(;i&&vis[i];i=edge[i].nxt);
fir[u]=i;
if(i) vis[i]=1,dfs(edge[i].v),ans[++cnt]=edge[i].u;
}
}
vector<int> work()
{
for(int i=1;i<=n*4;i++) if(id[i]!=od[i]) return {-1};
// printf("doing\n");
cnt=0;
dfs(1);
vector<int> w;
if(cnt!=n*4) return {-1};
for(int i=1;i<=4;i++) ans[i+cnt]=ans[i];
// for(int i=1;i<=cnt;i++) printf("%d%c",ans[i]," \n"[i==cnt]);
for(int i=ans[cnt]<=n*2?cnt:cnt-1;i>=1;i-=2) w.pb(ans[i]);
return w;
}
}et;
ll shsh(int id,int l,int r)
{
ll w1=h1.shsh(id,l,r);
ll w2=h2.shsh(id,l,r);
return (w1<<32)|w2;
}
ll thsh(int id,int l,int r)
{
ll w1=h1.thsh(id,l,r);
ll w2=h2.thsh(id,l,r);
return (w1<<32)|w2;
}
unordered_map<ll,int> id1;
unordered_map<ll,int> id2;
void work()
{
cin>>n>>m;
for(int i=1;i<=n;i++) cin>>s[i];
for(int i=1;i<=n;i++) cin>>t[i];
// chksame();
h1.init(1004535809,13131);
h2.init(998244353,23333);
for(int i=0;i<m;i++)
{
id1.clear();
id2.clear();
id1.reserve(n);
id2.reserve(n);
int cnt=n+n;
et.clear();
// printf("* %d\n",i);
for(int j=1;j<=n;j++)
{
ll w=shsh(j,1,i);
if(!id1[w]) id1[w]=++cnt;
// printf("%d %d\n",w,id1[w]);
et.addedge(id1[w],j);
w=shsh(j,i+1,m);
if(!id2[w]) id2[w]=++cnt;
et.addedge(j,id2[w]);
}
int ok=1;
for(int j=1;j<=n;j++)
{
ll w=thsh(j,1,m-i);
if(!id2[w]) ok=0;
et.addedge(id2[w],j+n);
w=thsh(j,m-i+1,m);
if(!id1[w]) ok=0;
// printf("%d %d\n",w,id1[w]);
et.addedge(j+n,id1[w]);
}
if(!ok) continue;
// printf("\n");
vector<int> w=et.work();
if(w[0]==-1) continue;
for(int i=w[0]<=n?0:1;i<(int)w.size();i+=2) printf("%d ",w[i]);
printf("\n");
for(int i=w[0]<=n?1:0;i<(int)w.size();i+=2) printf("%d ",w[i]-n);
printf("\n");
return ;
}
printf("-1\n");
}
signed main()
{
ios::sync_with_stdio(0),cin.tie(0);
int T; cin>>T; while(T--) work();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 25ms
memory: 175632kb
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: 337ms
memory: 174988kb
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)