QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#527091#7686. The Phantom Menace_HKSR_WA 644ms222508kbC++143.6kb2024-08-22 09:59:402024-08-22 09:59:41

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-08-22 09:59:41]
  • 评测
  • 测评结果:WA
  • 用时:644ms
  • 内存:222508kb
  • [2024-08-22 09:59:40]
  • 提交

answer

//#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <istream>
#include <string>
#include <queue>
#include <deque>
#include <random>
#include <stack>
#include <set>
#include <string.h>
#include <map>
#include <unordered_map>
#include <sstream>
#include <bitset>
#include <fstream>
#include <climits>
#include <time.h>
#include <cassert>
using namespace std;
#define int long long
#define ll long long
#define double long double
#define endl "\n"
#define pii pair<int,int>
#define p1(x) (x).first
#define p2(x) (x).second
#define i128 __int128_t
#define lc(x) (x<<1)
#define rc(x) (x<<1|1)
//#pragma GCC target("bitset")
//#pragma GCC optimize("Ofast,unroll-loops,inline")
const int N=1e6+10;
string a[N],b[N];
#define ull unsigned long long
int n,m;
vector<ull>ahs_pre[N],bhs_pre[N];
vector<ull>ahs_suf[N],bhs_suf[N];
const ull BS=131;
ull pw[1000300];
vector<pii>g[2*N];
inline bool prt(vector<int>A){
    if(A.size()!=2*n)return 0;
    int w=A[0]>n;
    for(int i=w;i<2*n;i+=2)
        cout<<A[i]<<" ";
    cout<<endl;
    for(int i=!w;i<2*n;i+=2)
        cout<<A[i]-n<<" ";
    cout<<endl;
    return 1;
}
signed main(){
    ios::sync_with_stdio(0);
//    freopen("/Users/liuyile/Downloads/shuffle/shuffle5.in","r",stdin);
//    freopen("/Users/liuyile/Downloads/binary/binary.out","w",stdout);
    int t;
    cin>>t;
    pw[0]=1;
    for(int i=1;i<=1e6;i++)
        pw[i]=pw[i-1]*BS;
    while(t--){
        cin>>n>>m;
        for(int i=1;i<=n;i++){
            cin>>a[i];
            ahs_pre[i].resize(m+1);
            ahs_suf[i].resize(m+1);
            ahs_pre[i][0]=0;
            for(int j=0;j<m;j++)
                ahs_pre[i][j+1]=ahs_pre[i][j]+pw[j]*a[i][j];
            ahs_suf[i][m]=0;
            for(int j=m-1;j>=0;j--)
                ahs_suf[i][j]=ahs_suf[i][j+1]*BS+a[i][j];
        }
        for(int i=1;i<=n;i++){
            cin>>b[i];
            bhs_pre[i].resize(m+1);
            bhs_suf[i].resize(m+1);
            bhs_pre[i][0]=0;
            for(int j=0;j<m;j++)
                bhs_pre[i][j+1]=bhs_pre[i][j]+pw[j]*b[i][j];
            bhs_suf[i][m]=0;
            for(int j=m-1;j>=0;j--)
                bhs_suf[i][j]=bhs_suf[i][j+1]*BS+b[i][j];
        }
        map<ull,int>mp;
        int cnt=0;
        bool ok=0;
        for(int lim=0;lim<m;lim++){
            mp.clear();
            for(int i=1;i<=cnt;i++)
                g[i].clear();
            cnt=0;
            
            for(int i=1;i<=n;i++){
                int l=ahs_pre[i][lim],r=ahs_suf[i][lim];
                if(m-lim==lim)r=r*BS+'*';
                if(!mp.count(l))mp[l]=++cnt;
                if(!mp.count(r))mp[r]=++cnt;
                g[mp[l]].push_back({mp[r],i});
            }
            
            for(int i=1;i<=n;i++){
                int l=bhs_pre[i][m-lim],r=bhs_suf[i][m-lim];
                if(m-lim==lim)l=l*BS+'*';
                if(!mp.count(l))mp[l]=++cnt;
                if(!mp.count(r))mp[r]=++cnt;
                g[mp[l]].push_back({mp[r],i+n});
            }
            int x=1;
            vector<int>A;
            while(!g[x].empty()){
                A.push_back(p2(g[x].back()));
                int y=p1(g[x].back());
                g[x].pop_back();
                x=y;
            }
            
            if(prt(A)){
                ok=1;
                break;
            }
        }
        if(!ok)cout<<-1<<endl;
        
    }
    
    fflush(stdout);
    cout.flush();
    return 0;
}
/*
 */

详细

Test #1:

score: 100
Accepted
time: 31ms
memory: 214472kb

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: 644ms
memory: 222508kb

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: 431ms
memory: 214504kb

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)