QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#572865#9319. Bull FarmEricWTL 400ms18972kbC++204.1kb2024-09-18 16:37:022024-09-18 16:37:06

Judging History

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

  • [2024-09-18 16:37:06]
  • 评测
  • 测评结果:TL
  • 用时:400ms
  • 内存:18972kb
  • [2024-09-18 16:37:02]
  • 提交

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; cin >> n >> l >> q;
	auto f = [](char ch1, char ch2) -> int {
		cin >> ch1 >> 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]] > 1) 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) cout << 1;
		else cout << 0;
	}
	cout << endl;
}

int main() {
	ios::sync_with_stdio(false);
    int T = 1; cin >> T;
    while (T--) solve();
    // system("pause");
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3584kb

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

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: 308ms
memory: 3688kb

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: 400ms
memory: 18972kb

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...

output:


result: