QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#374086#7686. The Phantom Menacearnold518WA 414ms365112kbC++174.4kb2024-04-02 11:35:142024-04-02 11:35:16

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-04-02 11:35:16]
  • 评测
  • 测评结果:WA
  • 用时:414ms
  • 内存:365112kb
  • [2024-04-02 11:35:14]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 2e6;

const int MOD = 998244353;
struct mint
{
    int x;
    mint() : x(0) {}
    mint(int _x) : x(_x) {}
    mint operator + (int ot) const { return x+ot>=MOD ? x+ot-MOD : x+ot; }
    mint operator - () const { return x ? MOD-x : 0; }
    mint operator - (int ot) const { return x<ot ? x+MOD-ot : x-ot; }
    mint operator * (int ot) const { return 1ll*x*ot%MOD; }
    mint operator += (int ot) { return *this = *this + ot; }
    mint operator -= (int ot) { return *this = *this - ot; }
    mint operator *= (int ot) { return *this = *this * ot; }
    operator int() const { return x; }
    bool operator < (int ot) const { return x<ot; }
    bool operator == (int ot) const { return x==ot; }
};
const mint P = 37;

int TC, N, M;
string A[MAXN+10], B[MAXN+10];
vector<mint> PA[MAXN+10], QA[MAXN+10];
vector<mint> PB[MAXN+10], QB[MAXN+10];

vector<pii> adj[MAXN+10];
vector<int> ans;
int deg[MAXN+10];

void dfs(int now)
{
    while(!adj[now].empty())
    {
        pii nxt=adj[now].back();
        adj[now].pop_back();
        dfs(nxt.first);
        ans.push_back(nxt.second);
    }
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);

    cin>>TC;
    while(TC--)
    {
        cin>>N>>M;
        for(int i=1; i<=N; i++) cin>>A[i], A[i]="?"+A[i];
        for(int i=1; i<=N; i++) cin>>B[i], B[i]="?"+B[i];

        for(int i=1; i<=N; i++)
        {
            PA[i]=vector<mint>(M+2);
            QA[i]=vector<mint>(M+2);

            mint val=1;
            for(int j=1; j<=M; j++)
            {
                val*=P;
                PA[i][j]=PA[i][j-1]+val*(A[i][j]-'a'+1);
            }
            for(int j=M; j>=1; j--)
            {
                QA[i][j]=(QA[i][j+1]+(A[i][j]-'a'+1))*P;
            }
        }
        for(int i=1; i<=N; i++)
        {
            PB[i]=vector<mint>(M+2);
            QB[i]=vector<mint>(M+2);

            mint val=1;
            for(int j=1; j<=M; j++)
            {
                val*=P;
                PB[i][j]=PB[i][j-1]+val*(B[i][j]-'a'+1);
            }
            for(int j=M; j>=1; j--)
            {
                QB[i][j]=(QB[i][j+1]+(B[i][j]-'a'+1))*P;
            }
        }

        bool flag2=false;
        for(int i=0; i<M; i++)
        {
            vector<mint> VA, VB;
            for(int j=1; j<=N; j++)
            {
                VA.push_back(PA[j][i]);
                VB.push_back(QA[j][i+1]);
            }
            sort(VA.begin(), VA.end());
            sort(VB.begin(), VB.end());
            VA.erase(unique(VA.begin(), VA.end()), VA.end());
            VB.erase(unique(VB.begin(), VB.end()), VB.end());

            bool flag=true;
            for(int j=1; j<=N; j++)
            {
                if(!binary_search(VA.begin(), VA.end(), QB[j][M-i+1])) { flag=false; break; }
                if(!binary_search(VB.begin(), VB.end(), PB[j][M-i])) { flag=false; break; }
            }
            if(!flag) continue;

            for(int j=1; j<=N; j++)
            {
                int v=(lower_bound(VA.begin(), VA.end(), QB[j][M-i+1])-VA.begin())+1;
                int u=(lower_bound(VB.begin(), VB.end(), PB[j][M-i])-VB.begin())+VA.size()+1;
                adj[u].push_back({v, -j});
                deg[u]++; deg[v]--;
            }
            for(int j=1; j<=N; j++)
            {
                int u=(lower_bound(VA.begin(), VA.end(), PA[j][i])-VA.begin())+1;
                int v=(lower_bound(VB.begin(), VB.end(), QA[j][i+1])-VB.begin())+VA.size()+1;
                adj[u].push_back({v, j});
                deg[u]++; deg[v]--;
            }

            for(int j=1; j<=N+N; j++) if(deg[j]!=0) flag=false;
            for(int j=1; j<=N+N; j++) deg[j]=0;
            if(!flag) continue;

            dfs(1);
            for(int j=1; j<=N+N; j++) adj[j].clear();
            if(ans.size()!=N+N)
            {
                ans.clear();
                continue;
            }

            flag2=true;
            reverse(ans.begin(), ans.end());
            for(auto it : ans) if(it>0) cout<<it<<" "; cout<<"\n";
            for(auto it : ans) if(it<0) cout<<-it<<" "; cout<<"\n";
            ans.clear();
            break;
        }
        if(!flag2) cout<<"-1\n";
    }
}

详细

Test #1:

score: 100
Accepted
time: 40ms
memory: 363596kb

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: 414ms
memory: 364992kb

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: 236ms
memory: 364108kb

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: -100
Wrong Answer
time: 295ms
memory: 365112kb

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

result:

wrong answer Jury has the answer but participant has not (test case 32)