QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#624982 | #7752. The Only Way to the Destination | Saton | WA | 0ms | 3580kb | C++20 | 2.4kb | 2024-10-09 17:03:12 | 2024-10-09 17:03:18 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define ff first
#define ss second
bool chmin(auto &a, auto b) { return b < a and (a = b, true); }
bool chmax(auto &a, auto b) { return a < b and (a = b, true); }
using i64 = long long;
void solve() {
int n, m, k;
cin >> n >> m >> k;
const int C = 2*k+1;
vector W(C + 1, vector<pair<int, int>>{});
for (int i = 0; i < k; i++) {
int x1, x2, y;
cin >> x1 >> x2 >> y;
if (y <= C) {
W[y].push_back({x1, x2});
}
}
if (n == 1) {
cout << "YES\n";
return;
}
if (m > C) {
cout << "NO\n";
return;
}
vector<pair<int, int>> lst;
int edg = 0, nod = 0;
for (int i = 1; i <= m; i++) {
vector<pair<int, int>> cur;
int l = 1;
sort(all(W[i]));
for (auto [a, b] : W[i]) {
if (l < a) {
cur.push_back({l, a - 1});
}
l = b + 1;
}
if (l <= n) {
cur.push_back({l, n});
}
if (0){
cerr << "l = " << l << '\n';
cerr << " i = " << i << '\n';
for (auto [a, b] : cur) {
cerr << a << ' ' << b << '\n';
}
cerr << "==\n";
}
nod += cur.size();
auto it = lst.begin();
for (auto [a, b] : cur) {
while (it != lst.end() and it->ff <= b) {
auto [x, y] = *it++;
x = max(x, a);
y = min(y, b);
if (x <= y) {
// cerr << " x = " << x << " y = " << y << "a = " << a << " b = " << b << '\n';
edg++;
if (y > x) {
cerr << "NO\n";
return;
}
}
}
if (it != lst.begin()) {
it--;
}
}
lst = move(cur);
}
// cerr << "edg = " << edg << '\n';
// cerr << "nod = " << nod << '\n';
if (edg == nod - 1) {
cerr << "YES\n";
} else {
cerr << "NO\n";
}
}
signed main() {
cin.tie(0)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3580kb
input:
5 3 2 2 5 1 1 4 3
output:
result:
wrong output format Unexpected end of file - token expected