QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#566571 | #9319. Bull Farm | ericmegalovania | WA | 0ms | 3680kb | C++20 | 3.8kb | 2024-09-16 00:33:17 | 2024-09-16 00:33:17 |
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<array<int,4>>b(m+1,array<int,4>{-1,-1,-1,-1});
for(int i=1;i<=m;i++){
static string s; cin>>s;
vector<int>vis(n+1);
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;
}
}
}
}
}
vector<vector<int>>e(n+1);
vector<int>scc(n+1);
auto UPDATE=[&]()->void{
scc.assign(n+1,0);
vector<int>dfn(n+1),low(n+1),inStack(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]) tarjan(tarjan,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[u]|=key[v];
}
};
for(int i=1;i<=col;i++){
key[i].reset();
key[i][i]=1;
}
for(int i=1;i<=col;i++){
dp(dp,i);
}
};
for(int i=1;i<=n;i++){
key[i].reset();
key[i][i]=1;
}
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++){
e[j].push_back(a[nw_c][j]);
}
}
else{
e[b[nw_c][1]].push_back(b[nw_c][3]);
e[b[nw_c][2]].push_back(b[nw_c][3]);
}
upd=1;
nw_c++;
}
debug("\tupd=%d\n",upd);
if(upd){
UPDATE();
}
ans[id]=key[scc[aa]][scc[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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3680kb
input:
2 5 2 4 0305040201 0404040404 030300 020500 050102 020501 6 2 4 030603010601 010203060504 030202 060402 050602 060401
output:
0011 0100
result:
wrong answer 1st lines differ - expected: '1011', found: '0011'