QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#573770 | #9319. Bull Farm | ericmegalovania | WA | 0ms | 3592kb | C++20 | 3.8kb | 2024-09-18 19:55:44 | 2024-09-18 19:55:44 |
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());
bitset<2001>key[2001];
void solve(){
int n=read(),m=read(),T=read();
vector<int>id(n+1);
iota(all(id),0);
vector a(m+1,vector<int>(n+1));
vector<array<int,3>>b(m+1,{-1,-1,-1});
for(int i=1;i<=m;i++){
static string s; cin>>s;
vector<int>cnt(n+1);
for(int j=1,k=0;j<=n;j++){
a[i][j]=(s[k]-'0')*50+(s[k+1]-'0');
k+=2;
cnt[a[i][j]]++;
}
int cnt1=0,cnt2=0;
for(int j=1;j<=n;j++){
if(cnt[j]==1) cnt1++;
if(cnt[j]==2) cnt2++;
}
if(cnt1==n){
b[i]={0,0,0};
}
else if(cnt1==n-2 && cnt2==1){
b[i]={0,0,0};
for(int j=1;j<=n;j++){
if(!cnt[j]) b[i][2]=j;
if(cnt[a[i][j]]==2){
if(!b[i][0]) b[i][0]=j;
else{
assert(!b[i][1]);
b[i][1]=j;
}
}
}
assert(b[i][0] && b[i][1] && b[i][2]);
}
}
vector<vector<int>>e(n+1);
auto addedge=[&](int u,int v)->void{
u=id[u],v=id[v];
if(u!=v) e[u].push_back(v);
};
int col=n;
auto UPDATE=[&]()->void{
int N=col,timStamp=0; col=0;
vector<int>dfn(N+1),low(N+1),inStack(N+1),scc(N+1);
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){
inStack[stk.top()]=0; stk.pop();
}
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());
}
swap(e,adj);
vector<vector<int>>rev(col+1);
vector<int>in(col+1);
for(int u=1;u<=col;u++){
for(auto v:e[u]){
rev[v].push_back(u);
in[u]++;
}
}
queue<int>p;
for(int i=1;i<=col;i++){
key[i].reset();
key[i][i]=1;
if(!in[i]) p.push(i);
}
while(p.size()){
auto u=p.front(); p.pop();
for(auto v:rev[u]){
key[v]|=key[u];
if(!--in[v]) p.push(v);
}
}
for(int i=1;i<=n;i++){
id[i]=scc[id[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;
}
}
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,iid]:q){
if(!c){
ans[iid]=(aa==bb);
continue;
}
debug("%d %d %d %d\n",aa,bb,c,iid);
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++){
addedge(j,a[nw_c][j]);
}
}
else{
addedge(b[nw_c][0],b[nw_c][2]);
addedge(b[nw_c][1],b[nw_c][2]);
}
upd=1;
nw_c++;
}
if(upd){
UPDATE();
}
ans[iid]=key[id[aa]][id[bb]];
}
for(auto x:ans){
cout<<x;
}
cout<<"\n";
}
int main(){
FAST_IO;
for(int T=read();T--;) solve();
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3592kb
input:
2 5 2 4 0305040201 0404040404 030300 020500 050102 020501 6 2 4 030603010601 010203060504 030202 060402 050602 060401
output:
1000 0000
result:
wrong answer 1st lines differ - expected: '1011', found: '1000'