QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#376542 | #5116. Contests | wjh213 | WA | 7ms | 20104kb | C++14 | 2.5kb | 2024-04-04 11:35:26 | 2024-04-04 11:35:26 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int const MAX=1e5+10;
int a[7][MAX],rk[7][MAX];
int bei[MAX][22][7];
int hou[7][MAX][7];
signed main(){
int n,m;
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++){
rk[i][a[i][j]]=j;
}
}
for(int i=1;i<=m;i++){
for(int j=1;j<=m;j++)hou[i][n][j]=a[i][n];
for(int j=n-1;j>=1;j--){
for(int k=1;k<=m;k++)hou[i][j][k]=a[i][j];
for(int k=1;k<=m;k++){
if(rk[k][hou[i][j+1][k]]<rk[k][hou[i][j][k]])hou[i][j][k]=hou[i][j+1][k];
}
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
bei[i][0][j]=hou[1][rk[1][i]][j];
//if(i==3)cerr<<i<<" "<<0<<" "<<j<<" "<<bei[i][0][j]<<" "<<1<<" "<<rk[j][i]<<" "<<j<<"\n";
}
for(int j=2;j<=m;j++){
for(int k=1;k<=m;k++){
if(rk[k][hou[j][rk[j][i]][k]]<rk[k][bei[i][0][k]])bei[i][0][k]=hou[j][rk[j][i]][k];
}
}
}
for(int i=1;i<=18;i++){
for(int j=1;j<=n;j++){
for(int l=1;l<=m;l++){
bei[j][i][l]=bei[bei[j][i-1][1]][i-1][l];
}
for(int k=2;k<=m;k++){
for(int l=1;l<=m;l++){
//i:倍增2的多少次方,j:哪个点往前走2^i步 k:从j能到的第k个队列中的最小值转移 l:刚才的最小值对应着五个结果
int &tp=bei[bei[j][i-1][k]][i-1][l],&my=bei[j][i][l];
if(rk[l][tp]<rk[l][my])my=tp;
}
}
}
}
//cerr<<hou[1][2][1]<<" "<<hou[1][2][2]<<" "<<hou[2][4][1]<<" "<<hou[2][4][2]<<" "<<rk[1][3]<<" "<<rk[2][3]<<"\n";
//for(int i=0;i<=4;i++){
// for(int j=1;j<=n;j++){
// for(int k=1;k<=m;k++){
// cerr<<j<<" "<<i<<" "<<k<<" "<<bei[j][i][k]<<"\n";
// }
// }
//}
int q;
cin>>q;
while(q--){
int s,t;
cin>>s>>t;
if(s==t){
cout<<0<<"\n";
continue;
}
int ans=0;
int now[]={0,s,s,s,s,s};
bool fl=true;
for(int i=1;i<=m;i++){
if(rk[i][bei[s][18][i]]<=rk[i][s]){
fl=false;
break;
}
}
if(fl){
cout<<-1<<"\n";
continue;
}
for(int i=17;i>=0;i--){
int tp[6];
memcpy(tp,now,sizeof(now));
for(int j=1;j<=m;j++){
for(int k=1;k<=m;k++){
int tp2=bei[now[j]][i][k];
if(rk[k][tp2]<rk[k][tp[k]])tp[k]=tp2;
}
}
bool fl=true;
for(int j=1;j<=m;j++){
if(rk[j][tp[j]]<rk[j][t]){
fl=false;
break;
}
}
if(fl)memcpy(now,tp,sizeof(tp)),ans+=(1<<i);
}
fl=true;
for(int i=1;i<=m;i++){
if(rk[i][now[i]]<rk[i][t]){
fl=false;
break;
}
}
if(fl)cout<<ans+2<<"\n";
else cout<<ans+1<<"\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 15836kb
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: 7ms
memory: 20104kb
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:
94 262145 1 1 1 21 1 153 262145 1 19 262145 25 1 1 1 80 1 1 1 1 262145 1 36 102 1 1 1 30 92 1 1 262145 37 36 60 1 1 1 1 1 1 1 1 16 262145 262145 1 1 262145 262145 1 1 140 1 1 77 1 60 1 1 1 4 90 1 1 262145 36 93 1 1 17 148 1 1 1 136 262145 262145 1 28 262145 262145 32 180 1 262145 262145 1 1 1 56 262...
result:
wrong answer 2nd numbers differ - expected: '-1', found: '262145'