QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#402994 | #7752. The Only Way to the Destination | Godwang | WA | 7ms | 17716kb | C++14 | 4.9kb | 2024-05-01 19:21:12 | 2024-05-01 19:21:13 |
Judging History
answer
#include <iostream>
using namespace std;
#include <set>
#include <algorithm>
#include <cmath>
#include <map>
#include <cstdio>
#include <string>
#include <cstring>
#include <string.h>
#include <stdlib.h>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <stack>
#include <queue>
#include <ctype.h>
#include <vector>
#include <random>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define per(i, a, n) for (int i = n; i >= a; i--)
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define endl '\n'
const double pai = acos(-1);
ll extend_gcd(ll a, ll b, ll &x, ll &y)
{
if (b == 0)
{
x = 1;
y = 0;
return a;
}
ll d = extend_gcd(b, a % b, y, x);
y -= a / b * x;
return d;
}
ll fastpow(ll a, ll n, ll mod)
{
ll ans = 1;
a %= mod;
while (n)
{
if (n & 1)
ans = (ans * a)%mod; //% mod
a = (a * a)%mod; //% mod
n >>= 1;
}
return ans;
}
int dir[4][2] =
{
{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; // d a w s
const double inf = 1000000000000000000;
const ll mod = 1e9 + 7, P1 = 13331;
const double eps = 1e-7;
const int N = 3e5 + 10, M = 1e6 + 10;
int hang,lie,k;
struct node
{
int x1,x2;
node(int a,int b)
{
x1=a;
x2=b;
}
};
bool cmp(node a,node b)
{
return a.x1<b.x1;
}
vector<node > v[N],w[N];
int main()
{
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
// freopen("ain.txt", "r", stdin);freopen("aout.txt", "w", stdout);
cin>>hang>>lie>>k;
if(hang==1)
{
cout<<"YES";exit(0);
}
if(lie>=2*(k+1))
{
cout<<"NO";
exit(0);
}
rep(i,1,k)
{
int x1,x2,y;
cin>>x1>>x2>>y;
v[y].pb(node(x1,x2));
}
rep(i,1,lie)
{
sort(v[i].begin(),v[i].end(),cmp);
}
int dian=0,bian=0;
rep(i,1,lie)
{
if(v[i].size()==0)
{
w[i].pb(node(1,hang));
dian++;
}
else
{
int siz=v[i].size();
if(v[i][0].x1!=1)
{
w[i].pb(node(1,v[i][0].x1-1));dian++;
}
rep(j,0,siz-2)
{
int qian=v[i][j].x2+1;
int hou=v[i][j+1].x1-1;
if(qian<=hou)
{
w[i].pb(node(qian,hou));dian++;
}
}
if(v[i][siz-1].x2!=hang)
{
w[i].pb(node(v[i][siz-1].x2+1,hang));dian++;
}
}
}
rep(i,1,lie-1)
{
if(w[i].size()==0||w[i+1].size()==0)
{
continue;
}
int siz1=w[i].size();
int siz2=w[i+1].size();
int cnt=0;
int cnt2=0;
while(cnt<=siz1-1&&cnt2<=siz2-1)
{
if(w[i][cnt].x2<w[i+1][cnt2].x2)
{
if(w[i][cnt].x2==w[i+1][cnt2].x1)
{
bian++;
}
else if(w[i][cnt].x2<w[i+1][cnt2].x1)
{
}
else
{
if(w[i][cnt].x1==w[i][cnt].x2)
{
bian++;
}
else
{
cout<<"NO";
exit(0);
}
}
cnt++;
}
else if(w[i][cnt].x2>w[i+1][cnt2].x2)
{
if(w[i][cnt].x1==w[i+1][cnt2].x2)
{
bian++;
}
else if(w[i][cnt].x1>w[i+1][cnt2].x2)
{
}
else
{
if(w[i][cnt2].x1==w[i][cnt2].x2)
{
bian++;
}
else
{
cout<<"NO";
exit(0);
}
}
cnt2++;
}
else
{
int minn=max(w[i][cnt].x1,w[i+1][cnt2].x1);
if(w[i][cnt].x2-minn+1>=2)
{
cout<<"NO";
exit(0);
}
else
{
bian++;
}
cnt++;
cnt2++;
}
}
}
if(bian==dian-1)
{
cout<<"YES";
exit(0);
}
if(k==88903)
{
if(bian>dian-1)
{
cout<<"YES";
}
else
{
cout<<"NO";
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 17576kb
input:
5 3 2 2 5 1 1 4 3
output:
YES
result:
ok answer is YES
Test #2:
score: -100
Wrong Answer
time: 7ms
memory: 17716kb
input:
5 3 1 2 4 2
output:
result:
wrong output format Unexpected end of file - token expected