QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#566577 | #9319. Bull Farm | ericmegalovania | TL | 89ms | 23072kb | C++20 | 3.7kb | 2024-09-16 00:34:26 | 2024-09-16 00:34:28 |
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);
}
};
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();
}
if(c) ans[id]=key[scc[aa]][scc[bb]];
else ans[id]=(aa==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: 0ms
memory: 3600kb
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: 3728kb
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: 82ms
memory: 3832kb
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: 0
Accepted
time: 89ms
memory: 23072kb
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:
000101000101100010001000000010010110000001000001001100000000010000100001000000101100000000010000001000000001110000010110100000111100100000001000000000011001010001000001001000100000000100011001100110010000010000101100000011111000000010000101010010000000010101000001010111100000100000000000000101000100...
result:
ok single line: '000101000101100010001000000010...0101000101000000000010101001000'
Test #5:
score: -100
Time Limit Exceeded
input:
1 2000 2000 1000000 FVAaH7GRPO;_11Da5J18@3SMG==\G8E8S^6:M4L0JH>MN5IXT>2<7WJ3U8LVJS=;;3F13>0D0>VOIIU@EPHG6ABL6;K?T1PXDERLG07]5C9^GDKG<SBMIW;`4W8P3=469TIPKH0O34523_J5C2MJ17D25Z@=K8H@M>WK<CMK7EO]BPD7B6AW741J5YIHIa1:ERSG>L3N2^F3<4F`DLE@2AA5=8GZK6:192FB736[WMV7:^DA2C:<LK040VJBM3M]WXU50`407TR_?PLF@5VL7OSL...