QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#726885#5116. ContestsYurilyWA 2ms20624kbC++202.4kb2024-11-09 09:59:172024-11-09 09:59:18

Judging History

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

  • [2024-11-09 09:59:18]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:20624kb
  • [2024-11-09 09:59:17]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int MAX=1E5+5;
int n,m,q;
int a[6][MAX],b[6][MAX];
int g[6][6][MAX],f[MAX][6][22],h[10],curh[10];
int main(){
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);
    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];
            b[i][a[i][j]]=j;
        }
            
    }

    for(int i=1;i<=m;++i){
        for(int j=1;j<=m;++j){
            g[i][j][b[i][n]]=a[j][b[i][n]];
            for(int k=n-1;k>=1;--k){
                g[i][j][b[i][k]]=min(g[i][j][b[i][k+1]],a[j][b[i][k]]);
            }
        }
    }

    for(int i=1;i<=n;++i){
        for(int j=1;j<=m;++j){
            f[i][j][0]=1e9;
            for(int k=1;k<=m;++k){
                f[i][j][0]=min(f[i][j][0],g[k][j][i]);
            }
 //           cout<<i<<" "<<j<<" "<<f[i][j][0]<<"\n";
        }
    }

    for(int k=1;k<=20;++k){
        for(int i=1;i<=n;++i){
            for(int j=1;j<=m;++j){
                f[i][j][k]=f[i][j][k-1];
                for(int l=1;l<=m;++l){
                    f[i][j][k]=min(f[i][j][k],f[b[l][f[i][l][k-1]]][j][k-1]);
                }
            }
        }
    }

    cin>>q;
    while(q--){
        int x,y;
        cin>>x>>y;
        bool flag=0;
        for(int i=1;i<=m;++i){
            if(a[i][x]<a[i][y]){
                cout<<1<<"\n";
                flag=1;
                break;
            }
        }
        if(flag)
            continue;
        
        for(int i=1;i<=m;++i)
            h[i]=a[i][x];
        
        int res=0;
        for(int i=20;i>=0;--i){
            for(int j=1;j<=m;++j){
                curh[j]=h[j];
                for(int k=1;k<=m;++k){
                    curh[j]=min(curh[j],f[b[k][h[k]]][j][i]);
                }
            }
            bool flag=0;
            for(int j=1;j<=m;++j){
                if(curh[j]<a[j][y]){
                    flag=1;
                    break;
                }
            }
            if(!flag){
                for(int j=1;j<=m;++j){
                    h[j]=curh[j];                   
                }
                res+=(1<<i);
            }
        }
        if(res<(1<<21)-1)
            cout<<res+2<<"\n";
        else    
            cout<<-1<<"\n";
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 13812kb

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:

1
2
5
3

result:

ok 4 number(s): "1 2 5 3"

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 20624kb

input:

998 5
1 2 6 3 4 5 7 11 8 9 14 12 13 10 15 16 18 19 20 17 23 22 21 26 24 25 27 29 30 28 32 31 34 33 37 38 39 35 40 36 41 43 42 46 44 48 45 47 51 49 50 56 52 57 53 54 55 62 58 59 63 64 60 65 66 61 67 69 70 68 71 73 74 75 72 78 77 79 82 76 81 85 84 80 86 87 83 88 90 91 89 92 96 98 94 95 97 101 93 103 1...

output:

82
-1
1
1
1
23
1
140
-1
1
18
-1
21
1
1
1
81
1
1
1
1
-1
1
30
102
1
1
1
28
80
1
1
-1
31
36
55
1
1
1
1
1
1
1
1
16
-1
-1
1
1
183
-1
1
1
129
1
1
67
1
51
1
1
1
2
90
1
1
-1
34
82
1
1
16
139
1
1
1
131
-1
-1
1
28
-1
-1
32
169
1
-1
-1
1
1
1
54
-1
64
23
110
114
1
-1
1
1
1
1
1
1
12
-1
1
-1
1
76
-1
114
-1
1
1
6
...

result:

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