QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#572821#9319. Bull FarmEricWRE 0ms0kbC++234.1kb2024-09-18 16:29:592024-09-18 16:29:59

Judging History

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

  • [2024-09-18 16:29:59]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-09-18 16:29:59]
  • 提交

answer

// Program written by EricWu ~~~
#include <bits/stdc++.h>
 
#define lowbit(x) (x & -x)
 
using namespace std;
 
inline char gc(void) {
    static char buf[100000], *p1 = buf, *p2 = buf;
    return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++;
}
 
#define gc() getchar()
 
template <class T> inline void read(T &x) {
    T f = 1; x = 0; static char c = gc();
    for (; !isdigit(c); c = gc()) if (c == '-') f = -f;
    for (; isdigit(c); c = gc()) x = x * 10 + (c & 15);
    if (f == -1) x = -x;
}
 
inline void readstr(char *s) {
    do *s = gc(); while ((*s == ' ') || (*s == '\n') || (*s == '\r'));
    do *(++s) = gc(); while ((~*s) && (*s != ' ') && (*s != '\n') && (*s != '\r'));
    *s = 0; return;
}
 
inline void readch(char&x) { while (isspace(x = gc())); }
 
char pf[100000], *o1 = pf, *o2 = pf + 100000;
#define ot(x) (o1 == o2 ? fwrite(pf, 1, 100000, stdout), *(o1 = pf) ++= x : *o1 ++= x)
template <class T>
inline void println(T x, char c = '\n') {
    if (x < 0) ot(45), x = -x;
    static char s[15], *b; b = s;
    if (!x) *b ++= 48;
    for (; x; * b ++= x % 10 + 48, x /= 10);
    for (; b-- != s; ot(*b)); ot(c);
}
 
template <class T> inline void write(T x) {
    if (x < 0) x = -x, putchar('-');
    if (x > 9) write(x / 10);
    putchar(x % 10 + 48);
}
 
template <class T> inline void writeln(T x, char c = '\n') { write(x); putchar(c); }
template <class T> inline void chkmax(T &x, const T y) { x > y ? x = x : x = y; }
template <class T> inline void chkmin(T &x, const T y) { x < y ? x = x : x = y; }
 
#define Ms(arr, opt) memset(arr, opt, sizeof(arr))
#define Mp(x, y) make_pair(x, y)
#define endl '\n'

typedef long long ll;
typedef pair <int, int> pii;
typedef array<int, 3> piii;
using i64 = long long;
const int inf = 1e9;

struct DSU {
    std::vector<int> f, siz;
    
    DSU() {}
    DSU(int n) {
        init(n);
    }
    
    void init(int n) {
        f.resize(n);
        std::iota(f.begin(), f.end(), 0);
        siz.assign(n, 1);
    }
    
    int find(int x) {
        while (x != f[x]) {
            x = f[x] = f[f[x]];
        }
        return x;
    }
    
    bool same(int x, int y) {
        return find(x) == find(y);
    }
    
    bool merge(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) {
            return false;
        }
        siz[x] += siz[y];
        f[y] = x;
        return true;
    }
    
    int size(int x) {
        return siz[find(x)];
    }
};

void solve() {
	int n, l, q; read(n), read(l), read(q);
	auto f = [](char ch1, char ch2) -> int {
		readch(ch1), readch(ch2);
		return 50 * (ch1 - 48) + (ch2 - 48);
	};
	DSU ds(n + 1);
	vector adj(n + 1, vector<pair<int, int>>());
	for (int i = 1;i <= l;i++) {
		ds.init(n + 1);
		vector<int> a(n + 1); map<int, int> mp;
		for (int j = 1;j <= n;j++) {
			char ch1, ch2;
			a[j] = f(ch1, ch2); mp[a[j]] ++;
		}
		if (mp.size() == n) {
			for (int j = 1;j <= n;j++) {
				if (ds.merge(j, a[j])) {
					adj[j].emplace_back(a[j], i);
					adj[a[j]].emplace_back(j, i);
				}
			}
		}
		else if (mp.size() == n - 1) {
			int x1, x2;
			for (int j = 1;j <= n;j++) {
				if (!mp.contains(j)) x1 = j;
				else if (mp[a[j]] == 2) x2 = j;
			}
			adj[x2].emplace_back(x1, i);
		}
	}
	vector dis(n + 1, vector<int>(n + 1, inf));
    for (int s = 1;s <= n;s++) {
		priority_queue<tuple<int, int>, vector<tuple<int, int>>,greater<>> q;
		dis[s][s] = 0;
		q.emplace(0, s);
		vector<bool> vis(n + 1, false); 
		while (q.size()) {
			auto [val, u] = q.top(); q.pop();
			if (vis[u]) continue;
			vis[u] = true;
			for (auto &[v, w] : adj[u]) {
				int newval = max(val, w);
				if (dis[s][v] > newval) {
					dis[s][v] = newval;
					q.emplace(newval, v);
				}
			}
		}
	}

	for (int i = 1;i <= q;i++) {
		char ch1, ch2; 
		int a = f(ch1, ch2), b = f(ch1, ch2), c = f(ch1, ch2);
		if (dis[a][b] <= c) writeln(1, ' ');
		else writeln(0, ' '); 
	}
	putchar('\n');
}

int main() {
    int T = 1; read(T);
    while (T--) solve();
    system("pause");
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Dangerous Syscalls

input:

2
5 2 4
0305040201
0404040404
030300
020500
050102
020501
6 2 4
030603010601
010203060504
030202
060402
050602
060401

output:


result: