QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#658386#7752. The Only Way to the DestinationTangWKWA 0ms3824kbC++202.9kb2024-10-19 16:44:312024-10-19 16:44:32

Judging History

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

  • [2024-10-19 16:44:32]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3824kb
  • [2024-10-19 16:44:31]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
struct node {
	int x1, x2, y;
};
struct point {
	int x1, x2;
	int num;
};
istream& operator >> (istream & in, struct node & x) {
	in >> x.x1 >> x.x2 >> x.y;
	return in;
}
void solve() {
	int n, m, k;
	cin >> n >> m >> k;
	int i, j;
	vector<node> a(k + 1);
	for(i = 1; i <= k; ++i) {
		// printf("rdb\n");
		cin >> a[i];
		// printf("Qwq\n");
		// cout << a[i].x1 << " " << a[i].x2 << " " << a[i].y << "wuwuw\n";
	}
	if(n == 1) {
		cout << "YES\n";
		return;
	}
	if(m > k + k + 1) {
		cout << "NO\n";
		return;
	}
	sort(a.begin() + 1, a.begin() + 1 + k, [&] (node & fr, node & ed) {
		if(fr.y == ed.y) {
			return fr.x1 < ed.x1;
		}
		return fr.y < ed.y;
	});
	vector<vector<node>> b(m + 1);
	vector<vector<point>> c(m + 1);
	for(i = 1; i <= k; ++i) {
		b[a[i].y].push_back(a[i]);
	}
	// for(i = 2; i <= m; ++i) {
	// 	if(b[i].size() == 0 && b[i - 1].size() == 0) {
	// 		cout << "NO\n";
	// 		return;
	// 	}
	// }
	int cnt = 0;//the num of point
	for(i = 1; i <= m; ++i) {
		auto now = b[i];
		if(now.size() == 0) {
			c[i].push_back((point){1, n, ++cnt});
		}else {
			int jend = now.size();
			if(now[0].x1 > 1) {
				c[i].push_back((point){1, now[0].x1 - 1, ++cnt});
			}
			for(int j = 0; j < jend - 1; ++j) {
				if(now[j].x2 + 1 >= now[j + 1].x1) {
					continue;
				}
				c[i].push_back((point){now[j].x2 + 1, now[j + 1].x1 - 1, ++cnt});
			}
			if(now[jend - 1].x2 < n) {
				c[i].push_back((point){now[jend - 1].x2 + 1, n, ++cnt});
			}
		}
		// for(auto& [x1, x2, num] : c[i]) {
		// 	cout << x1 << " " << x2 << " " << i << "qq\n";
		// }
	}
	// cout << "???\n";
	vector<vector<int>> edge(cnt + 1);
	for(i = 1; i < m; ++i) {
		auto b1 = c[i], b2 = c[i + 1];
		int t1 = b1.size(), t2 = b2.size();
		int i1 = 0, i2 = 0;
		while(i1 < t1 && i2 < t2) {
			if(b1[i1].x1 <= b2[i2].x2 && b1[i1].x2 >= b2[i2].x1) {
				int mi = max(b1[i1].x1, b2[i2].x1);
				int mx = min(b1[i1].x2, b2[i2].x2);
				if(mx - mi >= 2) {
					cout << "NO\n";
					return;
				}
				edge[b1[i1].num].push_back(b2[i2].num);
				edge[b2[i2].num].push_back(b1[i1].num);
				// printf("%d - > %d\n", b1[i1].num, b2[i2].num);
				if(b1[i1].x2 > b2[i2].x2) {
					++i2;
				}else {
					++i1;
				}
			}else if(b1[i1].x2 < b2[i2].x1) {
				++i1;
			}else {
				++i2;
			}
		}
	}
	bool flag = true;
	vector<int> vis(cnt + 1, 0);
	function<void(int,int)> dfs = [&] (int u, int fa) {
		// cout << u << "now\n";
		if(!flag) {
			return;
		}
		if(vis[u] == 1) {
			flag = false;
			return;
		}
		// cout << "??\n";
		vis[u] = 1;
		for(auto & v : edge[u]) {
			// cout << v << "tp\n";
			if(v != fa) {
				dfs(v, u);
			}
		}
	};
	dfs(1, -1);
	if(flag) {
		cout << "YES\n";
	}else {
		cout << "NO\n";
	}
}
int main() {
	ios_base::sync_with_stdio(false);
	solve();
	return 0;
}

详细

Test #1:

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

input:

5 3 2
2 5 1
1 4 3

output:

YES

result:

ok answer is YES

Test #2:

score: 0
Accepted
time: 0ms
memory: 3636kb

input:

5 3 1
2 4 2

output:

NO

result:

ok answer is NO

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3640kb

input:

2 4 2
2 2 1
1 1 4

output:

YES

result:

wrong answer expected NO, found YES