QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#376407#5116. ContestsfzxWA 8ms228924kbC++142.2kb2024-04-04 09:34:042024-04-04 09:34:05

Judging History

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

  • [2024-04-04 09:34:05]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:228924kb
  • [2024-04-04 09:34:04]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long 
using namespace std;
const int INF=1e5+5;
int n,m,a[7][INF],f[35][7][INF],aa[7][7][INF],p3[7][INF],ll[7];
signed main()
{
    ios::sync_with_stdio(false);
    cin>>n>>m;
    for (int i=1;i<=m;i++) {
        for (int j=1;j<=n;j++)
            cin>>a[i][j];
    }
    for (int i=1;i<=m;i++) {
        for (int j=1;j<=n;j++) p3[i][a[i][j]]=j;
        for (int p=1;p<=m;p++) {
            aa[i][p][n+1]=1e9;
            for (int j=n;j;j--) 
                aa[i][p][j]=min(aa[i][p][j+1],p3[i][a[p][j]]);    
        }
    }
    // p3[i][j] 表示 在 i 这场比赛中,j 这个点 的排名
    // aa[i][p][j] 在第 p 场比赛中, j 这个排名之后,在 i 这场比赛的最小值
    memset(f,63,sizeof f);
    for (int x=1;x<=m;x++)
        for (int y=1;y<=m;y++)
            for (int j=1;j<=n;j++)
                f[0][x][j]=min(f[0][x][j],aa[x][y][p3[y][j]]);
    for (int i=1;i<20;i++) {
        for (int x=1;x<=m;x++) {
            for (int y=1;y<=m;y++) {
                for (int j=1;j<=n;j++) {
                    f[i][x][j]=min(f[i-1][x][f[i-1][y][j]],f[i][x][j]);
                }
            }
        }
    }

    // cerr<<a[2][f[1][2][4]]<<" qwq?\n";
    int q=0;cin>>q;
    while (q--) {
        int l=0,r=0,res=0;
        cin>>l>>r;
        if (l==r) {cout<<"0\n";continue;}
        int fl5=0;
        for (int i=1;i<=m;i++)
            if (p3[i][l]<p3[i][r]) {cout<<"1\n";fl5=1;break;}
        if (fl5) continue;
        for (int u=1;u<=m;u++) ll[u]=l;
        int fl3=0;
        for (int p=19;~p;p--) {
            int fl2=0;
            for (int u=1;u<=m;u++) {
                if (f[p][u][ll[u]]>1e9) {fl2=1;continue;}
                int fl=0;
                for (int v=1;v<=m;v++) 
                    if (p3[v][a[u][f[p][u][ll[u]]]]<p3[v][r]) fl=1;
                if (fl) fl2=1;
            }
            if (fl2) fl3=1;
            else {
                res|=(1ll<<p);
                for (int u=1;u<=m;u++)
                    ll[u]=a[u][f[p][u][ll[u]]];
            }
        }
        if (!fl3) cout<<"-1\n"; 
        else cout<<res+2<<"\n";
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 206312kb

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: 8ms
memory: 228924kb

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:

55
-1
1
1
1
14
1
89
-1
1
12
-1
16
1
1
1
50
1
1
1
1
-1
1
23
61
1
1
1
18
53
1
1
-1
23
21
33
1
1
1
1
1
1
1
1
11
-1
-1
1
1
115
-1
1
1
81
1
1
44
1
33
1
1
1
3
55
1
1
-1
24
53
1
1
11
85
1
1
1
79
-1
-1
1
17
-1
-1
22
105
1
-1
-1
1
1
1
35
-1
43
16
67
70
1
-1
1
1
2
1
1
1
9
-1
1
-1
1
47
-1
73
-1
1
1
5
1
9
91
8
...

result:

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