답안 #1025838

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1025838 2024-07-17T10:41:54 Z AmirAli_H1 장난감 기차 (IOI17_train) C++17
0 / 100
8 ms 19292 KB
// In the name of Allah

#include <bits/stdc++.h>
#include "train.h"
using namespace std;

typedef		long long int			ll;
typedef		long double				ld;
typedef		pair<int, int>			pii;
typedef		pair<ll, ll>			pll;
typedef		complex<ld>				cld;

#define		all(x)					(x).begin(),(x).end()
#define		len(x)					((ll) (x).size())
#define		F						first
#define		S						second
#define		X						real()
#define		Y						imag()
#define		pb						push_back
#define		sep						' '
#define		endl					'\n'
#define		Mp						make_pair
#define		kill(x)					cout << x << '\n', exit(0)
#define		set_dec(x)				cout << fixed << setprecision(x);
#define		file_io(x,y)			freopen(x, "r", stdin); freopen(y, "w", stdout);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int maxn = 2e5 + 7;

int n, m;
vector<int> adj[maxn], adjr[maxn];
pii A[maxn]; bool M[maxn]; vector<int> res;
int mark[maxn], col[maxn], c = 0;
int val[maxn], valx[maxn], valr[maxn];
vector<int> ls[maxn], vc;

void dfs(int v) {
	mark[v] = 1;
	for (int u : adj[v]) {
		if (!mark[u]) dfs(u);
	}
	vc.pb(v);
}

void dfsr(int v) {
	mark[v] = 1; col[v] = c; ls[c].pb(v);
	for (int u : adjr[v]) {
		if (!mark[u]) dfsr(u);
	}
}

void scc() {
	for (int i = 0; i < n; i++) {
		if (!mark[i]) dfs(i);
	}
	reverse(all(vc));
	fill(mark, mark + n, 0);
	for (int i : vc) {
		if (!mark[i]) {
			dfsr(i); c++;
		}
	}
	
	for (int i = 0; i < c; i++) {
		if (len(ls[i]) > 1 || M[ls[i][0]]) valx[i] = 1;
	}
	for (int i = c - 1; i >= 0; i--) {
		for (int v : ls[i]) {
			for (int u : adj[v]) {
				if (valx[col[u]]) valx[i] = 1;
			}
		}
	}
	
	for (int i = 0; i < n; i++) {
		int j = col[i];
		if (A[i].S == 1) valr[j] = 1;
	}
	
	for (int i = 0; i < c; i++) {
		val[i] = (valr[i] && valx[i]);
	}
	for (int i = c - 1; i >= 0; i--) {
		for (int v : ls[i]) {
			for (int u : adj[v]) {
				if (val[col[u]]) val[i] = 1;
			}
		}
	}
}

vector<int> who_wins(vector<int> a, vector<int> r, vector<int> ux, vector<int> vx) {
	n = len(a); m = len(ux);
	for (int i = 0; i < n; i++) A[i] = Mp(a[i], r[i]);
	for (int i = 0; i < m; i++) {
		int u = ux[i], v = vx[i];
		adj[u].pb(v); adjr[v].pb(u);
		if (u == v) M[u] = 1;
	}
	res.resize(n);
	
	scc();
	for (int i = 0; i < n; i++) {
		int j = col[i];
		res[i] = val[j];
	}
	
	return res;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 19032 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 18012 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 19292 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 18980 KB 3rd lines differ - on the 696th token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 19036 KB 3rd lines differ - on the 2nd token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 19032 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -