QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#585585 | #9319. Bull Farm | xiao_xiao | WA | 435ms | 18212kb | C++20 | 5.2kb | 2024-09-23 21:20:29 | 2024-09-23 21:20:30 |
Judging History
answer
#include<bits/stdc++.h>
#define ull unsigned long long
#define lch(x) t[x].s[0]
#define rch(x) t[x].s[1]
#define INF 0x3f3f3f3f
#define ll long long
#define lll __int128
#define re register
#define inl inline
#define N 1000050
#define rx x<<1|1
#define lx x<<1
using namespace std;
inline int read(){
int w = 1 ,s = 0;
char ch = getchar();
while(!isdigit(ch)){
if(ch=='-') w = -1;
ch = getchar();
}
while(isdigit(ch)){
s = (s<<3)+(s<<1)+ch-'0';
ch = getchar();
}
return w*s;
}
struct query{
int time ,a ,b ,id ;
bool operator<(const query&a) const{
return time < a.time ;
}
} ;
int cnt ,cnt1 ,top ,n ;
int scc[N] ,low[N] ,dfn[N] ,isstk[N] ,stk[N] ,ind[N] ;
bitset<2005> f[2005] ;
std::vector<int> v[2005] ,adj[2005] ;
int g[N] ,F[N] ;
int find(int x){
if(x == g[x]) return x ;
return g[x] = find(g[x]) ;
}
void tarjan(int x){
dfn[x] = low[x] = ++ cnt ;
isstk[x] = 1 ,stk[++top] = x ;
for(auto v : adj[x]){
if(!dfn[v]){
tarjan(v) ;
low[x] = min(low[x],low[v]) ;
}
else if(isstk[v]) low[x] = min(low[x],dfn[v]) ;
}
if(dfn[x] == low[x]){
cnt1 ++ ;
int y ;
do{
y = stk[top--] ;
F[y] = x ;
isstk[y] = false ;
}while(y != x) ;
}
}
void getpath(){
for(int i = 1;i <= n;i ++ ) ind[i] = 0 ;
for(int i = 1;i <= n;i ++ ){
if(find(i) != i) continue ;
for(auto vv : adj[i]){
if(scc[vv] == scc[i] || find(vv) != vv) continue ;
v[find(vv)].push_back(find(i)) ;
ind[find(i)] ++ ;
}
}
}
void toposort(){
queue<int> q ;
for(int i = 1;i <= n;i ++ ) if(!ind[i] && find(i) == i) q.push(i) ;
while(!q.empty()){
int x = q.front() ;
q.pop() ;
for(auto to : v[x]){
f[to] |= f[x] ;
if(!--ind[to]) q.push(to) ;
}
}
}
void solve(){
int m ,q ;
cin >> n >> m >> q ;
std::vector<std::vector<int>> t(m+1) ;
std::vector<int> num(n+1) ,anx(q) ;
std::vector<query> Q(q) ;
auto get = [&](){
char s1 ,s2 ;
cin >> s1 >> s2 ;
int p1 = (s1 - 48) * 50 + s2 - 48 ;
return p1 ;
} ;
for(int i = 1;i <= n;i ++ ){
g[i] = i ;
adj[i].clear() ;
}
for(int i = 1;i <= m;i ++ ){
for(int j = 1;j <= n;j ++ ){
int p = get() ;
t[i].push_back(p) ;
}
}
cnt = cnt1 = n ;
for(int i = 1;i <= n;i ++ ) {
f[i].reset() ;
f[i][i] = 1 ;
scc[i] = i ;
dfn[i] = 0 ;
v[i].clear() ;
}
for(int i = 0;i < q;i ++ ) {
int a = get() ,b = get() ,c = get() ;
Q[i] = {c,a,b,i} ;
}
sort(Q.begin(),Q.end()) ;
int time = 0 ;
for(int i = 0;i < q;i ++ ){
while(time + 1 <= m && time + 1 <= Q[i].time){
time ++ ;
for(int i = 1;i <= n;i ++ ) num[i] = F[i] = 0 ;
for(auto val : t[time]) num[val] ++ ;
std::vector<std::vector<int>> nadj(n+1) ;
int sum = 0 ,px = 0 ;
// for(int i = 1;i <= n;i ++ ) {
// sum += !num[i] ;
// if(num[i] >= 2) px = i ;
// }
// if(!px){
// for(int i = 0;i < n;i ++ ){
// int to = t[time][i] ;
// if(find(i+1) != find(to)){
// adj[find(i+1)].push_back(find(to)) ;
// }
// }
// }
// else if(sum < 2) {
// int p = 0 ;
// for(int i = 0;i < n;i ++ ){
// if(!num[i+1]) p = i + 1 ;
// }
// if(p){
// for(int i = 0;i < n;i ++ ){
// if(t[time][i] == px && find(i+1) != find(p)){
// adj[find(i+1)].push_back(find(p)) ;
// }
// }
// }
// }
int mul = -1, zero = -1, ok = 1;
for (int j = 1; j <= n; ++j) {
if (num[j] == 2) {
if (mul == -1) mul = j;
else ok = 0;
}
if (num[j] == 0) {
if (zero == -1) zero = j;
else ok = 0;
}
}
if (!ok) continue;
if (mul == -1) {
for (int j = 1; j <= n; ++j) {
adj[find(j)].emplace_back(find(t[time][j-1]));
}
}
else for (int j = 1; j <= n; ++j) {
if (num[t[time][j-1]] == 2) {
adj[find(j)].emplace_back(find(zero));
}
}
for(int i = 1;i <= n;i ++ ) dfn[i] = num[i] = 0 ;
cnt = cnt1 = top = 0 ;
for(int i = 1;i <= n;i ++ ) if(!dfn[find(i)] && find(i) == i){
tarjan(find(i)) ;
}
for(int i = 1;i <= n;i ++ ){
int fa = find(i) ;
for(auto to : adj[i]){
int u = find(to) ;
if(F[i] != F[u]) nadj[F[i]].push_back(F[u]) ;
}
}
for(int i = 1;i <= n;i ++ ) {
sort(nadj[i].begin(),nadj[i].end()) ,nadj[i].erase(unique(nadj[i].begin(),nadj[i].end()),nadj[i].end()) ,adj[i] = nadj[i] ;
int u = find(i) ,v = find(F[i]) ;
g[u] = v ;
}
}
for(int i = 1;i <= n;i ++ ) v[i].clear() ,f[i].reset() ;
getpath() ;
for(int i = 1;i <= n;i ++ ) f[find(i)] |= 1 << i ;
toposort() ;
int a = find(Q[i].a) ,b = Q[i].b ,c = Q[i].time ;
// for(int i = 1;i <= cnt1;i ++ ) {
// for(int j = 1;j <= n;j ++ )cout << f[i][j] ;
// cout << endl ;
// }
// cout << a << ' ' << b << ' ' << c << endl ;
anx[Q[i].id] = f[a][b] ;
//cout << time << endl ;
}
for(int i = 0;i < q;i ++ ) cout << anx[i] ;
//cout << endl ;
cout << endl ;
}
int main(){
ios::sync_with_stdio(false);
int t ;
cin >> t ;
while(t -- )
solve() ;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 15940kb
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: 2ms
memory: 15928kb
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: 435ms
memory: 18212kb
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:
011100001101101111111111111111100101001111110111001110110110001011010101110111011111101101111011111110001011110111110111110101111111101010111110011110110111110001100111111011011111111111111011101011010111110111111111011110111110100101001011010100111110111111110011111100101111001110111011011101101110...
result:
wrong answer 1st lines differ - expected: '011110001101101111111111111111...1111111111111111101111111111111', found: '011100001101101111111111111111...1111110011111101101111010111101'