QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#456383 | #860. We apologize for any inconvenience | Kevin5307# | RE | 3ms | 8380kb | C++23 | 2.2kb | 2024-06-27 20:25:52 | 2024-06-27 20:25:53 |
Judging History
answer
//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
int n,k;
vector<int> stops[808];
int ind[808];
int dist[1505][808];
vector<int> G[808];
int ans[808];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--)
{
cin>>n>>k;
for(int i=1;i<=k;i++)
{
int s;
cin>>s;
stops[i].resize(s);
for(auto &x:stops[i])
cin>>x;
}
int s;
cin>>s;
for(int i=1;i<=k;i++)
ind[i]=s+1;
for(int i=1;i<=s;i++)
{
int x;
cin>>x;
ind[x]=i;
}
for(int i=1;i<=n;i++)
G[i].clear();
for(int i=1;i<=k;i++)
for(auto x:stops[i])
G[x].pb(i);
memset(ans,0,sizeof(ans));
for(int i=1;i<=n;i++)
{
memset(dist,0,sizeof(dist));
dist[i][0]=s+1;
priority_queue<array<int,3>> pq;
pq.push({s+1,i,0});
while(!pq.empty())
{
int d=pq.top()[0];
int u=pq.top()[1];
int c=pq.top()[2];
pq.pop();
if(d!=dist[u][c]) continue;
if(u<=n&&c<=n)
{
for(auto L:G[u])
{
int nd=min(d,ind[L]);
if(nd>dist[L+n][c+1])
{
dist[L+n][c+1]=nd;
pq.push({nd,L+n,c+1});
}
}
}
else
{
for(auto v:stops[u-n])
{
int nd=d;
if(nd>dist[v][c])
{
dist[v][c]=nd;
pq.push({nd,v,c});
}
}
}
}
for(int j=1;j<=n;j++) if(i!=j)
for(int k=1;k<=n;k++)
if(dist[j][k-1]<=dist[j][k])
{
for(int x=dist[j][k-1]+1;x<=dist[j][k];x++)
ans[x]=max(ans[x],k);
}
else dist[j][k]=dist[j][k-1];
}
for(int i=1;i<=s+1;i++)
cout<<ans[i]-1<<'\n';
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 8380kb
input:
1 5 4 3 1 3 5 2 1 4 2 2 3 2 2 4 3 1 4 3
output:
1 2 0 0
result:
ok 4 number(s): "1 2 0 0"
Test #2:
score: -100
Runtime Error
input:
35 20 20 2 2 13 2 2 9 7 10 3 9 15 5 11 4 9 16 19 15 4 17 18 5 3 8 8 12 20 16 11 18 9 6 4 12 4 18 15 17 6 16 19 14 7 5 20 9 3 8 14 4 5 14 7 9 17 5 3 17 11 20 15 19 11 16 5 8 13 15 20 18 9 10 14 7 4 3 13 19 10 17 6 8 15 9 4 12 20 7 14 16 5 4 12 11 6 18 14 20 17 18 4 8 15 11 16 14 6 5 13 19 3 8 3 10 8 ...