제출 #1318188

#제출 시각아이디문제언어결과실행 시간메모리
1318188HoriaHaivasToy (CEOI24_toy)C++20
9 / 100
23 ms14988 KiB
#include<bits/stdc++.h> #define debug(x) cerr << #x << " " << x << "\n" #define debugs(x) cerr << #x << " " << x << " " #pragma GCC optimize("Ofast") #define int long long using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int range_rng(int l, int r) { return uniform_int_distribution<int>(l,r)(rng); } bool wall[1505][1505]; bool visited[1505][1505]; int dp[1505][1505]; int nextl[1505][1505]; int nextr[1505][1505]; int nextu[1505][1505]; int nextd[1505][1505]; int n,m,k,l; bool inmat(int r, int c) { return ((r>0 && r<=n) && (c>0 && c<=m)); } void dfs(int r, int c) { if (visited[r][c]) return; visited[r][c]=1; ///mergem in jos int st,up; for (st=c-k+1; st<=c && st+k-1<=m; st++) { if (st>=1 && inmat(r+1,c) && nextl[r][c]<st && nextr[r][c]>st+k-1 && nextl[r+1][c]<st && nextr[r+1][c]>st+k-1 && !wall[r+1][c]) { dp[r+1][c]=1; dfs(r+1,c); } } ///mergem in sus for (st=c-k+1; st<=c && st+k-1<=m; st++) { if (st>=1 && inmat(r-1,c) && nextl[r][c]<st && nextr[r][c]>st+k-1 && nextl[r-1][c]<st && nextr[r-1][c]>st+k-1 && !wall[r-1][c]) { dp[r-1][c]=1; dfs(r-1,c); } } ///mergem la stanga for (up=r-l+1; up<=r && r+l-1<=n; up++) { if (up>=1 && inmat(r,c-1) && nextu[r][c]<up && nextd[r][c]>up+l-1 && nextu[r][c-1]<up && nextd[r][c-1]>up+l-1 && !wall[r][c-1]) { dp[r][c-1]=1; dfs(r,c-1); } } ///mergem la dreapta for (up=r-l+1; up<=r && r+l-1<=n; up++) { if (up>=1 && inmat(r,c+1) && nextu[r][c]<up && nextd[r][c]>up+l-1 && nextu[r][c+1]<up && nextd[r][c+1]>up+l-1 && !wall[r][c+1]) { dp[r][c+1]=1; dfs(r,c+1); } } } signed main() { /* ifstream fin("arbore.in"); ofstream fout("arbore.out"); */ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int i,j,xh,yh,xv,yv,r,c,last,fr,fc; char ch; cin >> m >> n >> k >> l; cin >> yh >> xh >> yv >> xv; yh++; xh++; yv++; xv++; for (i=1; i<=n; i++) { for (j=1; j<=m; j++) { cin >> ch; if (ch=='X') wall[i][j]=1; else wall[i][j]=0; if (ch=='*') { fr=i; fc=j; } } } for (i=1; i<=n; i++) { last=0; for (j=1; j<=m; j++) { if (wall[i][j]) last=j; nextl[i][j]=last; } last=m+1; for (j=m; j>=1; j--) { if (wall[i][j]) last=j; nextr[i][j]=last; } } for (j=1; j<=m; j++) { last=0; for (i=1; i<=n; i++) { if (wall[i][j]) last=i; nextu[i][j]=last; } last=n+1; for (i=n; i>=1; i--) { if (wall[i][j]) last=i; nextd[i][j]=last; } } r=xh; c=yv; dp[r][c]=1; dfs(r,c); if (dp[fr][fc]) cout << "YES\n"; else cout << "NO\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...