Submission #1125178

#TimeUsernameProblemLanguageResultExecution timeMemory
1125178cpptowinToy (CEOI24_toy)C++20
14 / 100
1597 ms112664 KiB
#include <bits/stdc++.h> #define fo(i, d, c) for (int i = d; i <= c; i++) #define fod(i, c, d) for (int i = c; i >= d; i--) #define maxn 1000010 #define N 1510 #define fi first #define se second #define pb emplace_back #define en cout << "\n"; #define int long long #define inf (int)1e18 #define bitcount(x) __builtin_popcountll(x) #define pii pair<int, int> #define vii vector<pii> #define lb(x) x & -x #define bit(i, j) ((i >> j) & 1) #define offbit(i, j) (i ^ (1LL << j)) #define onbit(i, j) (i | (1LL << j)) #define vi vector<int> #define all(x) x.begin(), x.end() #define ss(x) (int)x.size() #define UNIQUE(v) v.erase(unique(all(v)),v.end()) template <typename T1, typename T2> bool minimize(T1 &a, T2 b) { if (a > b) { a = b; return true; } return false; } template <typename T1, typename T2> bool maximize(T1 &a, T2 b) { if (a < b) { a = b; return true; } return false; } using namespace std; const int nsqrt = 450; const int mod = 1e9 + 7; void add(int &x, int k) { x += k; x %= mod; if(x < 0) x += mod; } void del(int &x, int k) { x -= k; x %= mod; if(x < 0) x += mod; } int n,m,k,l; int a[N][N],p[N][N]; pii s,t,f; int get(int l,int r,int u,int v) { return p[u][v] - p[l - 1][v] - p[u][r - 1] + p[l - 1][r - 1]; } bool save1(pii x) { return x.fi and x.fi <= n - k + 1 and x.se and x.se <= m and get(x.fi,x.se,x.fi + k - 1,x.se) == 0; } bool save2(pii x) { return x.fi and x.fi <= n and x.se and x.se <= m - l + 1 and get(x.fi,x.se,x.fi,x.se + l - 1) == 0; } bool save(pii x,pii y) { return x.fi <= y.fi and x.fi + k - 1 >= y.fi and y.se <= x.se and y.se + l - 1 >= x.se; } bool ok1(pii x) { return x.fi <= f.fi and x.fi + k - 1 >= f.fi and x.se == f.se; } bool ok2(pii x) { return x.fi == f.fi and x.se <= f.se and x.se + l - 1 >= f.se; } int dx[] = {1,-1,0,0}; int dy[] = {0,0,1,-1}; main() { #define name "TASK" if (fopen(name ".inp", "r")) { freopen(name ".inp", "r", stdin); freopen(name ".out", "w", stdout); } ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> m >> n >> l >> k; cin >> t.se >> t.fi >> s.se >> s.fi; t.fi++,t.se++,s.fi++,s.se++; // cout << t.fi << ' ' << t.se << ' ' << s.fi << ' ' << s.se;en; fo(i,1,n) fo(j,1,m) { char t;cin >> t; if(t == 'X') a[i][j] = 1; if(t == '*') f = {i,j}; p[i][j] = p[i - 1][j] + p[i][j - 1] - p[i - 1][j - 1] + a[i][j]; } // cout << f.fi << ' ' << f.se;en; map<pair<pii,pii>,bool> vis; queue<pair<pii,pii>> q; q.push({s,t}); while(ss(q)) { auto [x,y] = q.front(); q.pop(); if(ok1(x) and ok2(y)) { // cout << x.fi << ' ' << x.se << ' ' << y.fi << ' ' << y.se;en; return cout << "YES",0; } fo(k,0,3) { pii x1 = {x.fi + dx[k],x.se + dy[k]}; // cout << x1.fi << 'x' << x1.se << ' ' << y.fi << ' ' << y.se;en; if(save1(x1) and save(x1,y) and !vis.count({x1,y})) { // cout << x1.fi << ' ' << x1.se << ' ' << y.fi << ' ' << y.se;en; vis[{x1,y}] = 1; q.push({x1,y}); } pii y1 = {y.fi + dx[k],y.se + dy[k]}; if(save2(y1) and save(x,y1) and !vis.count({x,y1})) { // cout << x.fi << ' ' << x.se << ' ' << y1.fi << ' ' << y1.se;en; vis[{x,y1}] = 1; q.push({x,y1}); } } } cout << "NO"; }

Compilation message (stderr)

Main.cpp:87:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   87 | main()
      | ^~~~
Main.cpp: In function 'int main()':
Main.cpp:92:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   92 |         freopen(name ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:93:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   93 |         freopen(name ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#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...