Submission #1069942

#TimeUsernameProblemLanguageResultExecution timeMemory
1069942vjudge1Toy (CEOI24_toy)C++17
100 / 100
242 ms323408 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int MAX_N = 1500; int k, l, h, w; string grid[MAX_N]; bool intersect[MAX_N][MAX_N]; int up[MAX_N][MAX_N], down[MAX_N][MAX_N], lft[MAX_N][MAX_N], rght[MAX_N][MAX_N]; void func(int x, int y) { if(x+1 != h && grid[x+1][y] != 'X' && !intersect[x+1][y]) { int min_up = min(up[x+1][y], up[x][y]), min_down = min(down[x+1][y], down[x][y]), sum = min_up + min_down - 1; if(sum >= k) { intersect[x+1][y] = 1; func(x+1, y); } } if(x && grid[x-1][y] != 'X' && !intersect[x-1][y]) { int min_up = min(up[x-1][y], up[x][y]), min_down = min(down[x-1][y], down[x][y]), sum = min_up + min_down - 1; if(sum >= k) { intersect[x-1][y] = 1; func(x-1, y); } } if(y+1 != w && grid[x][y+1] != 'X' && !intersect[x][y+1]) { int min_left = min(lft[x][y+1], lft[x][y]), min_right = min(rght[x][y+1], rght[x][y]), sum = min_left + min_right - 1; if(sum >= l) { intersect[x][y+1] = 1; func(x, y+1); } } if(y && grid[x][y-1] != 'X' && !intersect[x][y-1]) { int min_left = min(lft[x][y-1], lft[x][y]), min_right = min(rght[x][y-1], rght[x][y]), sum = min_left + min_right - 1; if(sum >= l) { intersect[x][y-1] = 1; func(x, y-1); } } } void solve() { int x1, y1, x2, y2; cin >> w >> h >> k >> l >> x1 >> y1 >> x2 >> y2; int ex, ey; for(int i=0; i<h; ++i) { cin >> grid[i]; for(int j=0; j<w; ++j) { if(grid[i][j] == '*') ex = i, ey = j; } } intersect[y1][x2] = 1; for(int i=0; i<h; ++i) { up[i][0] = (grid[i][0] == 'X' ? 0 : 1); down[i][w-1] = (grid[i][w-1] == 'X' ? 0 : 1); for(int j=1; j<w; ++j) up[i][j] = (grid[i][j] == 'X' ? 0 : up[i][j-1] + 1); for(int j=w-2; j>=0; --j) down[i][j] = (grid[i][j] == 'X' ? 0 : down[i][j+1] + 1); } for(int i=0; i<w; ++i) { lft[0][i] = (grid[0][i] == 'X' ? 0 : 1); rght[h-1][i] = (grid[h-1][i] == 'X' ? 0 : 1); for(int j=1; j<h; ++j) lft[j][i] = (grid[j][i] == 'X' ? 0 : lft[j-1][i] + 1); for(int j=h-2; j>=0; --j) rght[j][i] = (grid[j][i] == 'X' ? 0 : rght[j+1][i] + 1); } func(y1, x2); cout << (intersect[ex][ey] ? "YES" : "NO") << endl; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; while(t--) solve(); }

Compilation message (stderr)

Main.cpp: In function 'void solve()':
Main.cpp:69:29: warning: 'ex' may be used uninitialized in this function [-Wmaybe-uninitialized]
   69 |    cout << (intersect[ex][ey] ? "YES" : "NO") << endl;
      |             ~~~~~~~~~~~~~~~~^
Main.cpp:69:29: warning: 'ey' may be used uninitialized in this function [-Wmaybe-uninitialized]
#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...