QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#592312 | #9319. Bull Farm | laonongmin | WA | 1327ms | 15292kb | C++17 | 3.8kb | 2024-09-26 21:52:41 | 2024-09-26 21:52:42 |
Judging History
answer
#pragma GCC optimize(3)
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define N 2005
#define Q 1000005
#define MOD 998244353
using namespace std;
vector<int> e[N];
int dfn[N], low[N], tot, st[N], inst[N], top, fa[N];
void tarjan(int u)
{
dfn[u] = low[u] = ++tot;
st[++top] = u; inst[u] = 1;
for(auto &&v:e[u])
{
if(!dfn[v])
{
tarjan(v);
low[u] = min(low[u], low[v]);
}
else if(inst[v]) low[u] = min(low[u], dfn[v]);
}
if(dfn[u] == low[u])
{
int v;
do{
v = st[top--]; inst[v] = 0;
fa[v] = u;
}while(v != u);
}
}
int rt(int x)
{
while(x!=fa[x]) x=fa[x]=fa[fa[x]];
return x;
}
bitset<N> vis;
void dfs(int u)
{
for(auto &&v:e[u])
{
if(vis[v]) continue;
vis[v]=1;
dfs(v);
}
}
int t[N][N];
int nt[N];
bitset<Q> ans;
struct query{
int a,b,id;
};
vector<query> qs[N];
char s[N];
map<pii,int> mp;
void solve()
{
int n,l,q;
cin>>n>>l>>q;
mp.clear();
for(int i=1;i<=n;++i) {e[i].clear(); fa[i]=i;}
for(int i=1;i<=l;++i) {qs[i].clear();}
for(int i=1;i<=l;++i)
{
cin>>s;
for(int j=1;j<=n;++j) t[i][j] = (s[2*(j-1)]-48)*50 + (s[2*(j-1)+1]-48);
}
for(int i=1;i<=q;++i)
{
cin>>s;
int a = (s[0]-48)*50 + (s[1]-48);
int b = (s[2]-48)*50 + (s[3]-48);
int c = (s[4]-48)*50 + (s[5]-48);
// cout<<a<<' '<<b<<' '<<c<<'\n';
qs[c].push_back({a,b,i});
}
for(auto &&[a,b,id]:qs[0]) ans[id]=(a==b);
for(int c=1;c<=l;++c)
{
// add
for(int i=1;i<=n;++i) nt[i] = 0;
int t1=0,t2=0;
int ok=2;
for(int i=1;i<=n;++i)
{
if(!nt[t[c][i]]) nt[t[c][i]] = i;
else
{
t1=i; t2=nt[t[c][i]];
ok -= 1;
}
}
if(!t1 && !t2)
{
for(int i=1;i<=n;++i)
{
if(rt(i) != rt(t[c][i]))
e[rt(i)].push_back(rt(t[c][i]));
}
}
else if(ok>0)
{
for(int i=1;i<=n;++i)
{
if(!nt[i])
{
int z=i;
t1=rt(t1), t2=rt(t2), z=rt(z);
if(t1 != z) e[t1].push_back(z);
if(t2 != z) e[t2].push_back(z);
break;
}
}
}
// tarjan
tot=0; top=0;
for(int i=1;i<=n;++i) {dfn[i]=0; inst[i]=0;}
for(int i=1;i<=n;++i) if(!dfn[i] && rt(i)==i) tarjan(i);
for(int i=1;i<=n;++i)
{
if(rt(i) != i && e[i].size())
{
for(auto &&v:e[i]) if(rt(v) != rt(i)) e[rt(i)].push_back(rt(v));
e[i].clear();
}
}
for(int i=1;i<=n;++i)
{
if(rt(i) == i)
{
for(auto &&v:e[i]) v=rt(v);
sort(e[i].begin(), e[i].end());
auto pos = unique(e[i].begin(), e[i].end());
e[i].erase(pos, e[i].end());
}
}
// cal
for(auto &&[a,b,id]:qs[c])
{
for(int i=1;i<=n;++i) vis[i]=0;
a=rt(a); b=rt(b);
vis[a]=1;
dfs(a);
ans[id] = vis[b];
}
}
// for(int i=1;i<=n;++i) cout<<rt(i)<<'\n';
for(int i=1;i<=q;++i) cout<<ans[i];
cout<<'\n';
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int T;
cin>>T;
while(T--)
{
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3824kb
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: 3876kb
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: 84ms
memory: 7208kb
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: 1327ms
memory: 15292kb
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:
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
result:
wrong answer 1st lines differ - expected: '000101000101100010001000000010...0101000101000000000010101001000', found: '000000000000000000000000000000...0000000000000000000000000000000'