QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#566378 | #9319. Bull Farm | ericmegalovania | WA | 87ms | 3772kb | C++20 | 4.2kb | 2024-09-15 23:58:54 | 2024-09-15 23:58:55 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ONLINE
#ifndef ONLINE
char DEBUG_BUFFER[1000];
#define debug(...) {sprintf(DEBUG_BUFFER,##__VA_ARGS__);cerr<<DEBUG_BUFFER;}
#else
#define debug(...) ;
#endif
using LL=long long;
using PII=pair<int,int>;
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()
#define FAST_IO {ios::sync_with_stdio(false);cin.tie(nullptr);}
inline int read(){static int x; cin>>x; return x;}
inline LL readLL(){static LL x; cin>>x; return x;}
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
#define N 2001
bitset<N>key[N];
void solve(){
int n=read(),m=read(),T=read();
vector a(m+1,vector<int>(n+1));
vector<int>fa(n+1);
iota(all(fa),0);
auto get=[&](int x)->int{
while(x!=fa[x]){
x=fa[x]=fa[fa[x]];
}
return x;
};
vector<array<int,4>>b(m+1,array<int,4>{-1,-1,-1,-1});
{
vector<int>vis(n+1);
for(int i=1;i<=m;i++){
static string s; cin>>s;
vis.assign(n+1,0);
bool flag=1,ok=1;
for(int j=1,k=0;j<=n;j++){
a[i][j]=(s[k]-'0')*50+(s[k+1]-'0');
k+=2;
vis[a[i][j]]++;
if(vis[a[i][j]]>1) flag=0;
if(vis[a[i][j]]>=3) ok=0;
}
if(flag){
b[i]={0,0,0,0};
}
else if(ok){
int cnt=0,empty;
for(int j=1;j<=n;j++){
if(vis[j]==2) cnt++;
else if(!vis[j]) empty=j;
}
if(cnt==1){
b[i]={1,0,0,empty};
for(int j=1;j<=n;j++){
if(vis[a[i][j]]==2){
if(!b[i][1]) b[i][1]=j;
else b[i][2]=j;
}
}
}
}
}
}
debug("\treadk ok\n");
vector<PII>E;
vector<vector<int>>e(n+1);
auto UPDATE=[&]()->void{
e.assign(n+1,{});
for(auto [u,v]:E){
e[get(u)].push_back(get(v));
}
vector<int>dfn(n+1),low(n+1),inStack(n+1),scc(n+1),siz(n+1);
int timStamp=0,col=0;
stack<int,vector<int>>stk;
auto tarjan=[&](auto&& self,int u)->void{
low[u]=dfn[u]=++timStamp;
stk.push(u),inStack[u]=1;
for(auto v:e[u]){
if(!dfn[v]){
self(self,v);
low[u]=min(low[u],low[v]);
}
else if(inStack[v]){
low[u]=min(low[u],low[v]);
}
}
if(dfn[u]==low[u]){
++col;
while(stk.top()!=u){
siz[scc[stk.top()]=col]++;
inStack[stk.top()]=0; stk.pop();
}
siz[scc[stk.top()]=col]++;
inStack[stk.top()]=0; stk.pop();
}
};
for(int i=1;i<=n;i++){
if(!dfn[i] && get(i)==i) tarjan(tarjan,i);
}
vector<int>id(col+1);
for(int i=1;i<=n;i++){
if(id[scc[i]]) fa[get(i)]=get(scc[i]);
id[scc[i]]=i;
}
for(int i=1;i<=col;i++){
id[i]=get(id[i]);
}
vector<vector<int>>adj(col+1);
for(int u=1;u<=n;u++){
for(auto v:e[u]){
if(scc[u]!=scc[v]){
adj[scc[u]].push_back(scc[v]);
}
}
}
for(int i=1;i<=col;i++){
sort(all(adj[i]));
adj[i].erase(unique(all(adj[i])),adj[i].end());
}
vector<int>vv(n+1);
auto dp=[&](auto&& self,int u)->void{
if(vv[u]) return;
vv[u]=1;
for(auto v:adj[u]){
self(self,v);
key[id[u]]|=key[id[v]];
}
};
for(int i=1;i<=n;i++){
key[i].reset();
key[i][i]=1;
}
for(int i=1;i<=col;i++){
dp(dp,i);
}
};
vector<array<int,4>>q(T); //[a,b,c,id]
for(int i=0;i<T;i++){
static string s; cin>>s;
q[i][3]=i;
for(int j=0,k=0;j<3;j++){
q[i][j]=(s[k]-'0')*50+(s[k+1]-'0');
k+=2;
}
debug("i=%d\n",i);
}
debug("\t read2 ok\n");
sort(all(q),[&](const array<int,4>& A,const array<int,4>& B)->bool{
return A[2]<B[2];
});
vector<int>ans(T);
int nw_c=1;
for(auto [aa,bb,c,id]:q){
debug("%d %d %d %d\n",aa,bb,c,id);
bool upd=0;
while(nw_c<=c){
debug("nw_c=%d\n",nw_c);
if(b[nw_c][0]==-1){
nw_c++;
continue;
}
if(b[nw_c][0]==0){
for(int j=1;j<=n;j++){
fa[get(j)]=get(a[nw_c][j]);
}
}
else{
E.push_back({b[nw_c][1],b[nw_c][3]});
E.push_back({b[nw_c][2],b[nw_c][3]});
}
upd=1;
nw_c++;
}
debug("\tupd=%d\n",upd);
if(upd){
UPDATE();
}
ans[id]=key[get(aa)][get(bb)]|(get(aa)==get(bb));
debug("\t;\n");
}
debug("\tok\n");
for(auto x:ans){
cout<<x;
}
cout<<"\n";
}
int main(){
FAST_IO;
for(int T=read();T--;) solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3732kb
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: 3720kb
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: 87ms
memory: 3772kb
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:
wrong answer 2nd lines differ - expected: '111111011101111011011111111111...1111110111111110111011110101111', found: '111111011111111011011111111111...1111110111111111111011110111111'