QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#573327 | #9319. Bull Farm | Sylvialline | WA | 24ms | 3876kb | C++14 | 2.2kb | 2024-09-18 18:10:48 | 2024-09-18 18:10:48 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
void solve();
int main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int t=1;
cin>>t;
while(t--)solve();
}
const int N=2003,M=1e6+3;
int a[N],b[N],f[N];
bool in[N];
int getf(int x){return x==f[x]?x:f[x]=getf(f[x]);}
vector<vector<pair<int,int>>>G;
void merge(int x,int y,int ti){
x=getf(x);y=getf(y);
if(x==y)return;
G[x].emplace_back(y,ti);
G[y].emplace_back(x,ti);
// cerr<<x<<" "<<y<<" "<<ti<<endl;
f[y]=x;
}
int mn[N][N],n,l;
void dijkstra(int x){
priority_queue<pair<int,int>>Q;
Q.emplace(0,x);
for(int i=1;i<=n;i++)mn[x][i]=l+1;
mn[x][x]=0;
while(Q.size()){
auto [t,u]=Q.top();
Q.pop();
t=-t;
if(t>mn[x][u])continue;
for(auto [v,ti]:G[u]){
if(ti<mn[x][v]){
mn[x][v]=ti;
Q.emplace(-ti,v);
}
}
}
}
void solve(){
int q;
cin>>n>>l>>q;
G.clear();G.resize(n+1);
for(int i=1;i<=n;i++){
f[i]=i;
}
for(int u=1;u<=l;u++){
string s;
cin>>s;
int x,y,z=0;
for(int j=1;j<=n;j++)b[j]=0;
for(int i=0,j=1;i<s.size();i+=2,j++){
a[j]=(s[i]-48)*50+s[i+1]-48;
if(b[a[j]]){
x=b[a[j]];
y=j;
}
b[a[j]]=j;
}
int ct=0;
for(int j=1;j<=n;j++)if(b[j]==0)z=j,++ct;
if(ct>1)continue;
if(z){
G[x].emplace_back(z,u);
G[y].emplace_back(z,u);
continue;
}
for(int i=1;i<=n;i++)in[i]=0;
for(int i=1;i<=n;i++){
if(in[i])continue;
for(int j=i,k=a[i];k!=i;j=k,k=a[k]){
in[a[k]]=1;
merge(j,k,u);
}
}
}
for(int i=1;i<=n;i++)dijkstra(i);
string res;
while(q--){
int a,b,c;
string s;
cin>>s;
a=(s[0]-48)*50+s[1]-48;
b=(s[2]-48)*50+s[3]-48;
c=(s[4]-48)*50+s[5]-48;
res+=(mn[a][b]<=c?'1':'0');
}
cout<<res<<endl;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3876kb
input:
2 5 2 4 0305040201 0404040404 030300 020500 050102 020501 6 2 4 030603010601 010203060504 030202 060402 050602 060401
output:
1011 0100
result:
ok 2 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
1 3 3 6 020202 030301 030201 020102 030203 010201 010303 020303 010202
output:
010101
result:
ok single line: '010101'
Test #3:
score: -100
Wrong Answer
time: 24ms
memory: 3600kb
input:
200 10 10 5000 01060:04020305080709 0103070:060204050908 09070503080401060:02 050308010204090:0607 03010502040607080:09 03080109020504060:07 06050:09040302080107 07080305010409060:02 030809010:0204060507 0:060908070201050304 060700 090:03 09080: 070405 010703 0:0100 080601 030600 070206 0:0:09 08040...
output:
011110101101111111111111111111111111111111110111111111111111111011010111111111111111111101111111111110111111110111111111111111111111111111111111111111111111110001110111111111111111111111111011101111111111111111111111111111111111111111111011110100111111111111111111111100111111101110111111111101111110...
result:
wrong answer 1st lines differ - expected: '011110001101101111111111111111...1111111111111111101111111111111', found: '011110101101111111111111111111...1111111111111111101111111111111'