QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#575765 | #9319. Bull Farm | nicnaknic | WA | 32ms | 38288kb | C++20 | 2.1kb | 2024-09-19 16:41:22 | 2024-09-19 16:41:22 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> PII;
#define x first
#define y second
const int N = 2100,M = N+N,INF = 1e18;
vector<PII> adj[N];
int dist[N],p[N];
int find(int x)
{
if(p[x]!=x) p[x] = find(p[x]);
return p[x];
}
int ans[N][N];
int n,l,q;
int ne[N],cnt[N];
bool st[N];
void solve() {
cin>>n>>l>>q;
for(int i = 1;i<=n;i++) p[i] = i,adj[i].clear();
for(int i = 1;i<=l;i++)
{
string str;
cin>>str;
for(int j = 1;j<=n;j++) cnt[j] = 0;
int pos = 0;
for(int j=0,k=1;j<str.size();j+=2,k++)
{
int x = ((str[j]-48)/50)*50+ (str[j+1]-48)%50;
ne[k] = x;
cnt[ne[k]]++;
}
int num = 0;
int pos2 = 0;
for(int j = 1;j<=n;j++)
{
if(!cnt[j]) pos= j;
if(cnt[j]==2) pos2 = j;
if(cnt[j]) num++;
}
if(num<n-1) continue;
//cout<<i<<" eee "<<endl;
if(num==n)
{
for(int j = 1;j<=n;j++)
{
int u = j,v= ne[j];
int fu=find(u),fv=find(v);
if(fu==fv) continue;
p[fu]=fv;
adj[u].push_back({v,i});
adj[v].push_back({u,i});
}
}
else
{
for(int j = 1;j<=n;j++)
if(ne[j]==pos2) adj[j].push_back({pos,i});
}
}
for(int s=1;s<=n;s++)
{
for(int j = 1;j<=n;j++)
{
st[j] =false;
ans[s][j] = INF;
dist[j] =INF;
}
priority_queue<PII,vector<PII>,greater<PII>> heap;
heap.push({0,s});
dist[s] = 0;
while(heap.size())
{
PII t = heap.top();
heap.pop();
int d = t.x,u=t.y;
if(st[u]) continue;
st[u] = true;
for(auto& [v,w]: adj[u])
{
if(dist[v]>max(d,w))
{
dist[v]= max(d,w);
heap.push({dist[v],v});
}
}
}
for(int j = 1;j<=n;j++) ans[s][j] =dist[j];
}
string r;
while(q--)
{
string str;
cin>>str;
int g[5]={0};
for(int j=0,k=1;j<str.size();j+=2,k++)
{
int x = ((str[j]-48)/50)*50+ (str[j+1]-48)%50;
g[k] =x;
//cout<<k<<" "<<x<<" q "<<endl;
}
if(ans[g[1]][g[2]]<=g[3]) r+='1';
else r+='0';
}
cout<<r<<"\n";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T = 1;
cin>>T;
while (T--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3720kb
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: 3844kb
input:
1 3 3 6 020202 030301 030201 020102 030203 010201 010303 020303 010202
output:
010101
result:
ok single line: '010101'
Test #3:
score: 0
Accepted
time: 32ms
memory: 3968kb
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:
011110001101101111111111111111111101111111110111011110110110111011010111111111111111111101111111111110111111110111111111111101111111111110111111111111111111110001100111111111111111111111111011101111111111111111111111111111111111111111011011110100111110111111110111111100111111101110111111111101111110...
result:
ok 200 lines
Test #4:
score: -100
Wrong Answer
time: 30ms
memory: 38288kb
input:
1 2000 1 1000000 M=:]A@8UAY7W2JJ4KEHIA[HSCQ1ENSC`JXR;F3PJ:_@41P9Z=9HR8P<<:DUXRR9^WOQFL?NZP6S@=J0^WE32=6;\U0?88]Q_RNPUMT6YU<4<S]H?:7OCQYOT4YAV1^764ENWSDBED>M7A:BI>KSIR48JQ9B=N\5T3N4A2aF0@>3TI81<G7;YE>W`NMP<:IT4CI3D0=GZC3I\CLQJQBA9BDIS9SAM55KaVA<Z@D=>:Y?CQHUQ5U3a6UVI8OKX9_FAF^7=5M85;<0;8YPAM<7Z7PP7A=N...
output:
100010000000100000000000000010010000000000000000001000100000001000000000000000000000000000000001000000000000000000000000000001000001100000000000100000000000000000000000010000000100000000000000000000000000000000000000000001000001000100000000000000000000000000000000000100000000000000001000000000000000...
result:
wrong answer 1st lines differ - expected: '000101000101100010001000000010...0101000101000000000010101001000', found: '100010000000100000000000000010...0000000001000000000000000000000'