제출 #1099929

#제출 시각아이디문제언어결과실행 시간메모리
1099929chaoslongMecho (IOI09_mecho)C++14
15 / 100
563 ms9564 KiB
// Calm down. // Think three times, code twice. #include "bits/stdc++.h" #define forr(_a,_b,_c) for(int _a = (_b); _a <= (_c); ++_a) #define ford(_a,_b,_c) for(int _a = (_b) + 1; _a --> (_c);) #define forf(_a,_b,_c) for(int _a = (_b); _a < (_c); ++_a) #define st first #define nd second #define ll long long #define ull unsigned long long #define pii pair <int,int> #define pll pair <ll,ll> #define piii pair <int,pii> #define vi vector <int> #define pb push_back #define mp make_pair #define all(x) begin(x),end(x) #define mask(i) (1LL << (i)) #define bit(x, i) (((x) >> (i)) & 1) #define bp __builtin_popcountll #define file "test" using namespace std; const int N = 2e5 + 5; const int mod = 1e9 + 7; // 998244353 const ll oo = 1e18; pii bd, en; int n, s, dx[] {1, -1, 0, 0}, dy[] {0, 0, 1, -1}, d[1005][1005], d1[1005][1005]; char a[1005][1005]; queue<piii> q; bool check(int x, int y) { if(x > n || x < 1 || y > n || y < 1 || a[x][y] == 'T') return false; return true; } bool kt(int mid) { memset(d1, 0, sizeof d1); q.push({mid * s, {bd.st, bd.nd}}); while(q.size()) { int dxy = q.front().st, x = q.front().nd.st, y = q.front().nd.nd; q.pop(); if(d1[x][y]) continue; d1[x][y] = 1; forr(i, 0, 3) { int nx = x + dx[i], ny = y + dy[i]; if(!check(nx, ny)) continue; if((dxy + 1) % s == 0 && (dxy + 1) / s < d[nx][ny]) { q.push({dxy + 1, {nx, ny}}); } else if((dxy + 1) % s != 0) { q.push({dxy + 1, {nx, ny}}); } } } return d1[en.st][en.nd]; } void to_nho_cau() { cin >> n >> s; memset(d, 63, sizeof d); forr(i, 1, n) { forr(j, 1, n) { cin >> a[i][j]; if(a[i][j] == 'H') { d[i][j] = 0; q.push({0, {i, j}}); } if(a[i][j] == 'M') bd = {i, j}; if(a[i][j] == 'D') en = {i, j}; } } while(q.size()) { int dxy = q.front().st, x = q.front().nd.st, y = q.front().nd.nd; q.pop(); if(d[x][y] < dxy) continue; forr(i, 0, 3) { int nx = x + dx[i], ny = y + dy[i]; if(!check(nx, ny) || a[nx][ny] == 'D') continue; if(dxy + 1 < d[nx][ny]) { d[nx][ny] = dxy + 1; q.push({dxy + 1, {nx, ny}}); } } } int l = 0, r = mod, ans = -1; while(l <= r) { int mid = (l + r) >> 1; if(kt(mid)) { ans = mid; l = mid + 1; } else r = mid - 1; } cout << ans << "\n"; } signed main(){ ios_base::sync_with_stdio(0);cin.tie(0); // #ifdef LOCAL // freopen(file".inp","r",stdin); // freopen(file".out","w",stdout); // #endif int t = 1; //cin >> t; while(t--) to_nho_cau(); } /* 1.self check: 2.long long 3.size of array 4.code for testing 5.initializing 6.modulo number */ /** ∧__∧ (`•ω• )づ__∧ (つ  /( •ω•。) しーJ (nnノ) pat pat **/ /** /\_/\ * (= ._.) * / >☕ \>💻 **/

컴파일 시 표준 에러 (stderr) 메시지

mecho.cpp:119:9: warning: "/*" within comment [-Wcomment]
  119 | /**  /\_/\
      |
#Verdict Execution timeMemoryGrader output
Fetching results...