QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#585225#9319. Bull Farmxiao_xiaoTL 181ms20352kbC++204.1kb2024-09-23 19:48:022024-09-23 19:48:02

Judging History

你现在查看的是最新测评结果

  • [2024-09-23 19:48:02]
  • 评测
  • 测评结果:TL
  • 用时:181ms
  • 内存:20352kb
  • [2024-09-23 19:48:02]
  • 提交

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] ;

int tot ;
int head[N] ,edge[N] ,ver[N] ,nxt[N] ;
bitset<2005> f[2005] ;

std::vector<int> v[2005] ;

inl void add(int x,int y){
	edge[++tot] = y ;
	nxt[tot] = head[x] ;
	head[x] = tot ;
}

void tarjan(int x){
	dfn[x] = low[x] = ++ cnt ;
	isstk[x] = 1 ,stk[++top] = x ;
	for(int i = head[x];i;i = nxt[i]){
		int v = edge[i] ;
		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--] ;
			scc[y] = cnt1 ;
			f[scc[y]] |= 1 << y ;
			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 ++ ){
		for(int j = head[i];j;j = nxt[j]){
			int vv = edge[j] ;
			if(scc[vv] == scc[i]) continue ;
			v[scc[vv]].push_back(scc[i]) ;
			ind[scc[i]] ++ ;
		}
	}
}

void toposort(){
	queue<int> q ;
	for(int i = 1;i <= cnt1;i ++ ) if(!ind[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 ;
	tot = 0 ;
	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) ;
	std::vector mp(n+1,std::vector<int>(n+1)) ;

	auto get = [&](){
		char s1 ,s2 ;
		cin >> s1 >> s2 ;
		int p1 = (s1 - 48) * 50 + s2 - 48 ;
		return p1 ;
	} ;

	for(int i = 1;i <= m;i ++ ){
		for(int j = 1;j <= n;j ++ ){
			int p = get() ;
			t[i].push_back(p) ;
			//cout << p << " \n"[j == n] ;
		}
	}
	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(auto val : t[time]) num[val] ++ ;
			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(scc[i+1] != scc[to] && !mp[i+1][to]){
						add(i+1,to) ;
						mp[i+1][to] = 1 ;
					}
				}
			}
			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 && scc[i+1] != scc[p] && !mp[i+1][p]){
							add(i+1,p) ;
							mp[i+1][p] = 1 ;
						}
					}
				}
			}
			for(int i = 1;i <= n;i ++ ) dfn[i] = num[i] = 0 ;
			for(int i = 1;i <= cnt1;i ++) f[i].reset() ;
			cnt = cnt1 = top = 0 ;
			for(int i = 1;i <= n;i ++ ) if(!dfn[i]){
				tarjan(i) ;
			}
		}
		for(int i = 1;i <= n;i ++ ) v[i].clear() ;
		getpath() ;
		toposort() ;
		int a = scc[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 ;

		//cout << cnt1 << 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 ;
	for(int i = 1;i <= n;i ++ ) head[i] = 0 ;
}

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: 2ms
memory: 17940kb

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: 18004kb

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: 181ms
memory: 20352kb

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: -100
Time Limit Exceeded

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:


result: