Submission #533468

# Submission time Handle Problem Language Result Execution time Memory
533468 2022-03-06T06:08:08 Z Stro256 Mecho (IOI09_mecho) C++14
84 / 100
173 ms 6360 KB
#include<bits/stdc++.h>
using namespace std;

#define FOR(i,a,b) for(int i = (a) ; i<(b) ; i++)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for(int i = (b)-1 ; i>=(a) ; i--)
#define R0F(i,a) ROF(i,0,a)
#define REP(a) F0R(_,a)
#define each(e,a) for(auto &e : (a))
#define sz(v) (int)(v).size()
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define rsz resize
#define pb push_back
#define f first
#define s second
#define pf push_front
#define ft front()
#define bk back()
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define tcT template<class T
#define tcTU tcT, class U
#define nl "\n"

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using pi = pair<int,int>;
using vpi = vector<pi>;
using str = string;
using vs = vector<str>;
using db = long double;
using pl = pair<ll,ll>;
using pd = pair<db,db>;
tcT> using V = vector<T>;
tcT> using pqg = priority_queue<T,vector<T>,greater<T>>;
tcTU> using PR = pair<T,U>;

const int MOD = 1e9+7;
const ll INF = 1e18;
const int dx[] = {-1,0,1,0}, dy[] = {0,-1,0,1};

constexpr int bits(int x) { return x == 0 ? 0 : 31 - __builtin_clz(x); }
constexpr bool onbit(int msk, int i) { return msk>>i&1; }
constexpr ll p2(int x) { return 1LL<<x; }
constexpr int pct(int x) { return __builtin_popcount(x); }
constexpr int lg2(int x) { return x == 0 ? 0 : 31 - __builtin_clz(x); }; //int only

tcT> bool ckmin(T&a, const T&b) { return b < a ? a = b,1 : 0; }
tcT> bool ckmax(T&a, const T&b) { return b > a ? a = b,1 : 0; }

ll cdiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); }
ll fdiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); }

tcTU> T fstTrue(T lo, T hi, U f) {
    hi++; assert(lo <= hi);
    while (lo < hi) {
        T mid = lo+(hi-lo)/2;
        f(mid) ? hi = mid : lo = mid+1;
    }
    return lo;
}
tcTU> T lstTrue(T lo, T hi, U f) {
    lo--; assert(lo <= hi);
    while (lo < hi) {
        T mid = lo+(hi-lo+1)/2;
        f(mid) ? lo = mid : hi = mid-1;
    }
    return lo;
}

tcT> void remDup(V<T> &v) {
    sort(all(v)); v.erase(unique(all(v)), end(v)); }
void DBG() { cerr << "]\n"; }
template<class H, class... T> void DBG(H h, T... t) {
    cerr << h; if(sizeof...(t)) cerr << ", ";
    DBG(t...);
}
#ifdef LOCAL
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif // LOCAL

void setPrec() { cout << fixed << setprecision(16); }
void setIO(string NAME = "") {
    cin.tie(0)->sync_with_stdio(0);
    setPrec();
    if(sz(NAME)) {
        freopen((NAME + ".inp").c_str(),"r",stdin);
        freopen((NAME + ".out").c_str(),"w",stdout);
    }
}

const int MX = 805;
int N, S, si, sj, ei, ej;
str g[MX];
int d[MX][MX], d1[MX][MX];

bool isInside(int x, int y)  {
    return min(x,y)>=0 && max(x,y)<N;
}

void bfs(int dis[MX][MX], int st) {
    queue<pi> q;
    F0R(i,N) F0R(j,N) if(!dis[i][j]) q.push({i,j});
    while(!q.empty()) {
        int x = q.ft.f, y = q.ft.s; q.pop();
        if(st>=0 && dis[x][y]/S + st >= d1[x][y]) continue;
        F0R(i,4) {
            int nx = x + dx[i], ny = y + dy[i];
            if(isInside(nx, ny) && (g[nx][ny]!='T') && (st>=0 || g[nx][ny] != 'D') && dis[nx][ny]>=MOD) {
                q.push({nx, ny});
                dis[nx][ny] = dis[x][y] + 1;
            }
        }
    }
}

void solve() {
    cin>>N>>S;
    F0R(i,N) cin>>g[i];
    memset(d1, 0x3f, sizeof d1);
    F0R(i,N) F0R(j,N) {
        if(g[i][j] == 'M') {
            si = i, sj = j;
        }
        else if(g[i][j] == 'H') {
            d1[i][j] = 0;
        }
        else if(g[i][j] == 'D') {
            ei = i, ej = j;
        }
    }
    bfs(d1, -1);
    int lo = 0, hi = MX*MX+1;
    while(lo<hi) {
        int mid = lo + (hi-lo+1)/2;
        memset(d, 0x3f, sizeof d);
        d[si][sj] = 0;
        bfs(d, mid);
        if(d[ei][ej] < MOD) lo = mid;
        else hi = mid-1;
    }
    cout << lo << nl;
}

int main() {
    setIO();

    int t=1;
    //cin>>t;
    while(t-->0) {
        solve();
    }

    return 0;
}

Compilation message

mecho.cpp: In function 'void setIO(std::string)':
mecho.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 + ".inp").c_str(),"r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mecho.cpp:94:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   94 |         freopen((NAME + ".out").c_str(),"w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5324 KB Output is correct
2 Correct 4 ms 5324 KB Output is correct
3 Correct 4 ms 5368 KB Output is correct
4 Correct 4 ms 5324 KB Output is correct
5 Correct 4 ms 5324 KB Output is correct
6 Correct 4 ms 5324 KB Output is correct
7 Correct 72 ms 6096 KB Output is correct
8 Incorrect 4 ms 5324 KB Output isn't correct
9 Correct 3 ms 5408 KB Output is correct
10 Correct 3 ms 5324 KB Output is correct
11 Correct 4 ms 5324 KB Output is correct
12 Correct 3 ms 5324 KB Output is correct
13 Correct 4 ms 5324 KB Output is correct
14 Incorrect 4 ms 5324 KB Output isn't correct
15 Correct 3 ms 5324 KB Output is correct
16 Correct 3 ms 5324 KB Output is correct
17 Correct 3 ms 5324 KB Output is correct
18 Correct 4 ms 5324 KB Output is correct
19 Correct 4 ms 5324 KB Output is correct
20 Correct 5 ms 5324 KB Output is correct
21 Correct 4 ms 5324 KB Output is correct
22 Correct 4 ms 5324 KB Output is correct
23 Correct 4 ms 5324 KB Output is correct
24 Correct 4 ms 5324 KB Output is correct
25 Correct 4 ms 5416 KB Output is correct
26 Correct 4 ms 5324 KB Output is correct
27 Correct 4 ms 5324 KB Output is correct
28 Correct 3 ms 5324 KB Output is correct
29 Correct 4 ms 5324 KB Output is correct
30 Correct 4 ms 5420 KB Output is correct
31 Correct 4 ms 5324 KB Output is correct
32 Correct 4 ms 5324 KB Output is correct
33 Correct 7 ms 5452 KB Output is correct
34 Correct 7 ms 5544 KB Output is correct
35 Correct 21 ms 5452 KB Output is correct
36 Correct 8 ms 5580 KB Output is correct
37 Correct 9 ms 5580 KB Output is correct
38 Correct 25 ms 5580 KB Output is correct
39 Correct 9 ms 5580 KB Output is correct
40 Correct 9 ms 5580 KB Output is correct
41 Correct 40 ms 5532 KB Output is correct
42 Correct 9 ms 5580 KB Output is correct
43 Correct 9 ms 5668 KB Output is correct
44 Correct 38 ms 5580 KB Output is correct
45 Correct 14 ms 5708 KB Output is correct
46 Correct 12 ms 5708 KB Output is correct
47 Correct 49 ms 5708 KB Output is correct
48 Correct 11 ms 5708 KB Output is correct
49 Correct 11 ms 5796 KB Output is correct
50 Correct 60 ms 5788 KB Output is correct
51 Correct 14 ms 5768 KB Output is correct
52 Correct 15 ms 5832 KB Output is correct
53 Correct 69 ms 5836 KB Output is correct
54 Correct 15 ms 5876 KB Output is correct
55 Correct 14 ms 5832 KB Output is correct
56 Correct 79 ms 5836 KB Output is correct
57 Correct 19 ms 6012 KB Output is correct
58 Correct 17 ms 5964 KB Output is correct
59 Correct 89 ms 5964 KB Output is correct
60 Correct 22 ms 5964 KB Output is correct
61 Correct 23 ms 5964 KB Output is correct
62 Correct 109 ms 6064 KB Output is correct
63 Correct 88 ms 6068 KB Output is correct
64 Correct 173 ms 5992 KB Output is correct
65 Correct 143 ms 5964 KB Output is correct
66 Correct 118 ms 5964 KB Output is correct
67 Incorrect 106 ms 6064 KB Output isn't correct
68 Correct 43 ms 6012 KB Output is correct
69 Correct 39 ms 6020 KB Output is correct
70 Correct 44 ms 6096 KB Output is correct
71 Correct 34 ms 6012 KB Output is correct
72 Correct 28 ms 6016 KB Output is correct
73 Correct 30 ms 6360 KB Output is correct
74 Correct 61 ms 6344 KB Output is correct
75 Correct 56 ms 6344 KB Output is correct
76 Correct 56 ms 6348 KB Output is correct
77 Correct 60 ms 6356 KB Output is correct
78 Incorrect 71 ms 6240 KB Output isn't correct
79 Correct 41 ms 6220 KB Output is correct
80 Correct 53 ms 6236 KB Output is correct
81 Correct 57 ms 6220 KB Output is correct
82 Correct 55 ms 6220 KB Output is correct
83 Correct 68 ms 6232 KB Output is correct
84 Correct 62 ms 6220 KB Output is correct
85 Correct 72 ms 6188 KB Output is correct
86 Correct 69 ms 6276 KB Output is correct
87 Correct 70 ms 6280 KB Output is correct
88 Correct 77 ms 6232 KB Output is correct
89 Correct 74 ms 6152 KB Output is correct
90 Correct 78 ms 6112 KB Output is correct
91 Correct 73 ms 6236 KB Output is correct
92 Correct 70 ms 6228 KB Output is correct