QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#286963#5116. Contestssio_WA 0ms40604kbC++141.7kb2023-12-19 09:53:412023-12-19 09:53:42

Judging History

你现在查看的是最新测评结果

  • [2023-12-19 09:53:42]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:40604kb
  • [2023-12-19 09:53:41]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
int n,m,q,a[6][maxn],pos[6][maxn];
struct node{int a[6];}f[17][maxn];
node mmin(node a,node b){node ans;for(int i=1;i<=m;i++) ans.a[i]=min(a.a[i],b.a[i]);return ans;}
node init(int x){node ans;for(int i=1;i<=m;i++) ans.a[i]=pos[i][x];return ans;}
bool check(node a,node b)
{
    for(int i=1;i<=m;i++) if(a.a[i]<b.a[i]) return 1;
    return 0;
}
void output(node a)
{
    for(int i=1;i<=m;i++) cout<<a.a[i]<<" ";
    cout<<"\n";
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>n>>m;
    for(int i=1;i<=m;i++)
        for(int j=1;j<=n;j++) cin>>a[i][j],pos[i][a[i][j]]=j;
    for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) f[0][i].a[j]=1e9;
    for(int i=1;i<=m;i++)
    {
        node tmp=init(a[i][n]);
        f[0][a[i][n]]=mmin(f[0][a[i][n]],tmp);
        output(tmp);
        for(int j=n-1;j>=1;j--) tmp=mmin(tmp,init(a[i][j])),f[0][a[i][j]]=mmin(f[0][a[i][j]],tmp);
    }
    for(int i=1;i<=16;i++)
    {
        for(int j=1;j<=n;j++)
        {
            f[i][j]=f[i-1][j];
            for(int k=1;k<=m;k++) f[i][j]=mmin(f[i][j],f[i-1][a[k][f[i-1][j].a[k]]]);
        }
    }
    cout<<"\n";
    for(int i=1;i<=n;i++,cout<<"\n")
        for(int j=1;j<=m;j++) cout<<f[1][i].a[j]<<" ";
    cin>>q;
    while(q--)
    {
        int x,y,ans=0;
        cin>>x>>y;
        node s=init(x),t=init(y);
        if(check(s,t)==1){cout<<1<<"\n";continue;}
        for(int i=16;i>=0;i--)
        {
            node tmp=s;
            for(int k=1;k<=m;k++) tmp=mmin(tmp,f[i][a[k][s.a[k]]]);
            if(check(tmp,t)==0) s=tmp,ans+=(1<<i);
        }
        if(ans>n) cout<<-1<<"\n";
        else cout<<ans+2<<"\n";
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 40604kb

input:

6 2
1 3 2 5 4 6
2 1 4 3 6 5
4
1 4
5 3
6 1
5 2

output:

6 5 
4 6 

1 1 
1 1 
1 1 
2 1 
2 3 
4 3 
1
2
5
3

result:

wrong answer 1st numbers differ - expected: '1', found: '6'