QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#624901 | #7752. The Only Way to the Destination | Saton | WA | 0ms | 3556kb | C++20 | 1.6kb | 2024-10-09 16:51:32 | 2024-10-09 16:51:32 |
Judging History
answer
///by Saton.
#include<bits/stdc++.h>
#define PI acos(-1)
#define fi first
#define se second
#define sz(a) ((int)a.size())
#define all(a) a.begin(), a.end()
#define int long long
#define rep(i,a,b) for(int i = (a);i <= (b);i ++)
#define lep(i,a,b) for(int i = (a);i >= (b);i --)
#define FLUSH fflush(stdout)
using namespace std;
typedef pair<int,int> PII;
int n,m,k;
bool solve() {
cin >> n >> m >> k;
const int N = 2*k+1;
vector<vector<PII>> w(N+1);
rep(i,1,k) {
int x1,x2,y;
cin >> x1 >> x2 >> y;
if(y<=N) w[i].push_back({x1,x2});
}
if(n==1) return true;
if(m>k) return false;
int edge = 0,node = 0;
vector<PII> lst,cur;
rep(i,1,m) {
sort(all(w[i]));
cur.clear();
int l = 1;
for(auto [x1,x2] : w[i]) {
cur.push_back({l,x1-1});
l = x2+1;
}
if(l<=n) cur.push_back({l,n});
node += sz(cur);
auto it = lst.begin();
for(auto [curl,curr] : cur) {
while(it!=lst.end() && it->fi<=curr) {
auto [lstl,lstr] = *it ++;
int l = max(curl,lstl),r = min(curr,lstr);
if(l==r) edge ++;
if(l<r) return false;
}
if(it!=lst.end()) {
it --;
}
}
lst = cur;
}
return (node == edge-1);
}
signed main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
if(solve()) cout << "YES";
else cout << "NO";
}
/* /\_/\
* (= ._.)
* / > \>
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3556kb
input:
5 3 2 2 5 1 1 4 3
output:
NO
result:
wrong answer expected YES, found NO