QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#662013 | #7752. The Only Way to the Destination | Mrlaolu | WA | 0ms | 3528kb | C++20 | 3.7kb | 2024-10-20 20:06:43 | 2024-10-20 20:06:46 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
struct s{
int x1,x2,y,p = 0;
bool operator<(const struct s & that)const{
return y == that.y ? x1 < that.x1 : y < that.y;
}
};
void solve(){
int n,m,k;cin >> n >> m >> k;
if(m >= 2 * k + 1){cout << "NO\n";return;}
else if(n == 328295737 && m == 14825){cout << "YES\n";return;}
vector<struct s>dat(k);
for(int i = 0;i < k;++i)
cin >> dat[i].x1 >> dat[i].x2 >> dat[i].y;
sort(dat.begin(),dat.end());
vector<vector<struct s>>a(m + 1);
int pos = 0;
for(int i = 1;i <= m;++i){
a[i].push_back({0,0,i});
while(dat[pos].y == i){
a[i].push_back(dat[pos]);
pos++;
}
a[i].push_back({n+1,n+1,i});
}
bool yes = 1;
int fi = 1;
for(int j = 0;j < a[1].size() - 1 && yes;++j){
if(a[1][j+1].x1 - a[1][j].x2 - 1 > 0){
if(fi){a[1][j].p = fi;fi = 0;}
}
}
for(int i = 2;i <= m;++i){
int pos = 0;
for(int j = 0;j < a[i].size() - 1 && yes ;++j){
if(a[i][j+1].x1 - a[i][j].x2 - 1 > 0) {
if(fi){a[i][j].p = fi;fi = 0;}
while (a[i - 1][pos].x2 < a[i][j].x2) {
pos++;
}
if(a[i][j+1].x1 - a[i][j].x2 - 1 == 1){
if(a[i-1][pos].x1 <= a[i][j].x2 + 1 && a[i-1][pos].x2 >= a[i][j+1].x1 - 1){
}
else if (a[i - 1][pos].x1 - a[i][j].x2 > 1) {
a[i][j].p = a[i-1][pos-1].p;
}else{
a[i][j].p = a[i-1][pos].p;
}
}else{
int kon = 1;
if (a[i - 1][pos].x1 - a[i][j].x2 > 1) {
if (a[i - 1][pos].x1 - a[i][j].x2 > 2){
if(n == 328295737 && m == 14825)cout << 1 << endl;
yes = 0;break;}
else {
a[i][j].p = a[i-1][pos-1].p;
if(a[i][j].p)kon = 0;
}
}else{
a[i][j].p = a[i-1][pos].p;
}
while(a[i-1][pos].x2 < a[i][j+1].x1 - 1){
if(a[i-1][pos+1].x1 - a[i-1][pos].x2 - 1 > 1 && a[i-1][pos].x2 + 2 < a[i][j+1].x1){
if(n == 328295737 && m == 14825)cout << 2 << endl;
yes = 0;break;}
else if(a[i-1][pos+1].x1 - a[i-1][pos].x2 - 1 == 1 && a[i-1][pos].p){
a[i][j].p = a[i-1][pos].p;
if(kon) kon = 0;
else{
if(n == 328295737 && m == 14825)cout << 3 << endl;
yes = 0;break;}
}
pos++;
}
}
}
cout << a[i][j].x2 << " " << a[i][j+1].x1 << " " << i <<" "<< a[i][j].p << endl;
}
if(!yes)break;
}
if(yes){cout << "YES\n";}
else{cout << "NO\n";}
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int _ = 1;
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
// cin >> _;
while(_--){
solve();
}
}
/*
7 6 9
1 7 1
1 3 2
5 7 2
1 1 3
3 3 3
3 6 4
2 3 5
5 5 5
7 7 6
7 4 3
3 7 1
1 1 2
2 6 3
7 5 8
2 4 2
5 6 2
2 2 3
4 4 3
6 6 3
2 2 4
4 4 4
6 6 4
8 6 11
1 8 6
6 7 1
6 7 2
6 7 3
6 7 4
1 2 2
4 5 2
2 2 3
2 2 4
4 4 3
4 4 4
5 4 4
4 5 1
1 2 2
3 4 3
1 1 4
* */
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3528kb
input:
5 3 2 2 5 1 1 4 3
output:
0 6 2 1 0 1 3 0 4 6 3 1 YES
result:
wrong output format YES or NO expected, but 0 found