QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#283942 | #5116. Contests | yhddd | WA | 0ms | 44556kb | C++14 | 1.6kb | 2023-12-15 19:09:53 | 2023-12-15 19:09:53 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int maxn=100010;
const int inf=1e9;
inline int read(){
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch-48);ch=getchar();}
return x*f;
}
int n,m,q;
int a[6][maxn],b[6][maxn];
int f[18][maxn][6];
int p[6],p1[6];
void work(){
n=read();m=read();
for(int i=1;i<=m;i++){
for(int j=1;j<=n;j++){
a[i][j]=read(),b[i][a[i][j]]=j;
}
}
memset(f[0],0x3f,sizeof(f[0]));
for(int i=1;i<=m;i++){
for(int j=1;j<=m;j++){
int mn=n+1;
for(int k=n;k;k--){
mn=min(mn,b[j][a[i][k]]);
f[0][k][j]=min(f[0][k][j],mn);
}
}
}
for(int i=1;i<=17;i++){
for(int j=1;j<=n;j++){
for(int k=1;k<=m;k++){
f[i][j][k]=f[i-1][j][k];
for(int l=1;l<=m;l++){
f[i][j][k]=min(f[i][j][k],f[i-1][a[l][f[i-1][j][l]]][k]);
}
}
}
}
q=read();
while(q--){
int u=read(),v=read(),fl=0,fl1=0,ans=2;
for(int i=1;i<=m;i++){
p[i]=b[i][u];
if(p[i]<b[i][v]){fl=1;break;}
}
if(fl){printf("1\n");continue;}
for(int i=17;~i;i--){
for(int j=1;j<=m;j++){
p1[j]=p[j];
for(int k=1;k<=m;k++)p1[j]=min(p1[j],f[i][a[k][p[k]]][j]);
}
fl=0;
for(int j=1;j<=m;j++){
if(p1[j]<b[j][v]){fl=1;break;}
}
if(!fl){
for(int j=1;j<=m;j++)p[j]=p1[j];
ans+=(1<<i);
}
else fl1=1;
}
if(!fl1)printf("-1\n");
else printf("%d\n",ans);
}
}
int T;
signed main(){
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
T=1;
while(T--)work();
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 43984kb
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: 44556kb
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:
-1 -1 1 1 1 26 1 -1 -1 1 25 -1 34 1 1 1 109 1 1 1 1 -1 1 -1 133 1 1 1 40 -1 1 1 -1 -1 41 -1 1 1 1 1 1 1 1 1 22 -1 -1 1 1 -1 -1 1 1 -1 1 1 -1 1 -1 1 1 1 4 115 1 1 -1 45 -1 1 1 24 -1 1 1 1 -1 -1 -1 1 36 -1 -1 45 -1 1 -1 -1 1 1 1 76 -1 -1 29 -1 -1 1 -1 1 1 2 1 1 1 17 -1 1 -1 1 100 -1 -1 -1 1 1 10 1 -1 ...
result:
wrong answer 1st numbers differ - expected: '94', found: '-1'