Submission #500023

# Submission time Handle Problem Language Result Execution time Memory
500023 2021-12-30T09:37:16 Z Nartifact Mecho (IOI09_mecho) C++14
7 / 100
35 ms 7780 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define forinc(i,a,b) for(int i=a;i<=b;++i)
#define fordec(i,a,b) for(int i=a;i>=b;--i)
#define pb push_back
#define eb emplace_back
#define pii pair <int,int>
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int N = 888, inf = 1e15;
const int H[] = {1, 0, -1, 0};
const int C[] = {0, 1, 0, -1};
int n, s, cti = inf;
char a[N][N];
int t[N][N];
bool cx[N][N];
pii sta, fin;

bool valid (const int& x, const int& y)
{
    return x && y && x <= n && y <= n
          && a[x][y] != 'T';
}

struct adt {int x, y, step;};

bool ok (const int& tg)
{
    queue <adt> q;
    q.push({sta.fi, sta.se, 0});
    cx[sta.fi][sta.se] = 1;
    while(q.size()) {
        auto tmp = q.front(); q.pop();
        if(tmp.x == fin.fi && tmp.y == fin.se) return 1;
        forinc(i,0,3) {
            int nh = tmp.x + H[i];
            int nc = tmp.y + C[i];
            if(valid(nh, nc) && !cx[nh][nc] && (tmp.step + 1) / s <= t[nh][nc] - tg) {
                q.push({nh, nc, tmp.step + 1});
                cx[nh][nc] = 1;
            }
        }
    }
    return 0;
}

void solve ()
{
    queue <pii> q;
    forinc(i,1,n) forinc(j,1,n) {
        t[i][j] = inf;
        if(a[i][j] == 'H') {
            q.push({i, j});
            t[i][j] = 0;
        }
        else if(a[i][j] == 'M') sta = {i, j};
        else if(a[i][j] == 'D') fin = {i, j};
    }

    // bfs bee
    while(q.size()) {
        auto x = q.front(); q.pop();
        forinc(i,0,3) {
            int nh = x.fi + H[i];
            int nc = x.se + C[i];
            if(valid(nh, nc) && t[nh][nc] > t[x.fi][x.se] + 1) {
                t[nh][nc] = t[x.fi][x.se] + 1;
                q.push({nh, nc});
            }
        }
    }

    // binary search
    int l = 0, r = n * n, ans = -1;
    while(l <= r) {
        int mid = l + r >> 1;
        if(ok(mid)) {
            ans = mid;
            l = mid + 1;
        }
        else r = mid - 1;
    }
    cout << ans;
}

void read ()
{
    cin >> n >> s;
    forinc(i,1,n) forinc(j,1,n)
        cin >> a[i][j];
    solve();
}

main ()
{
	#define task "ioi09_mecho"
	cin.tie(0) -> sync_with_stdio(0);
	if(fopen (task ".inp", "r")) {
		freopen (task ".inp", "r", stdin);
		freopen (task ".out", "w", stdout);
	}
    read();
	return 0;
}

Compilation message

mecho.cpp: In function 'void solve()':
mecho.cpp:82:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   82 |         int mid = l + r >> 1;
      |                   ~~^~~
mecho.cpp: At global scope:
mecho.cpp:100:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  100 | main ()
      | ^~~~
mecho.cpp: In function 'int main()':
mecho.cpp:105:11: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  105 |   freopen (task ".inp", "r", stdin);
      |   ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
mecho.cpp:106:11: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  106 |   freopen (task ".out", "w", stdout);
      |   ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Incorrect 0 ms 332 KB Output isn't correct
3 Correct 0 ms 332 KB Output is correct
4 Incorrect 0 ms 332 KB Output isn't correct
5 Incorrect 0 ms 332 KB Output isn't correct
6 Incorrect 0 ms 332 KB Output isn't correct
7 Incorrect 25 ms 6860 KB Output isn't correct
8 Correct 0 ms 332 KB Output is correct
9 Incorrect 0 ms 332 KB Output isn't correct
10 Incorrect 0 ms 332 KB Output isn't correct
11 Correct 0 ms 332 KB Output is correct
12 Incorrect 0 ms 588 KB Output isn't correct
13 Incorrect 1 ms 588 KB Output isn't correct
14 Correct 1 ms 588 KB Output is correct
15 Incorrect 1 ms 320 KB Output isn't correct
16 Incorrect 1 ms 344 KB Output isn't correct
17 Incorrect 0 ms 460 KB Output isn't correct
18 Incorrect 0 ms 460 KB Output isn't correct
19 Incorrect 0 ms 460 KB Output isn't correct
20 Incorrect 0 ms 460 KB Output isn't correct
21 Incorrect 0 ms 460 KB Output isn't correct
22 Incorrect 0 ms 460 KB Output isn't correct
23 Incorrect 1 ms 588 KB Output isn't correct
24 Incorrect 1 ms 588 KB Output isn't correct
25 Incorrect 1 ms 588 KB Output isn't correct
26 Incorrect 1 ms 588 KB Output isn't correct
27 Incorrect 1 ms 588 KB Output isn't correct
28 Incorrect 0 ms 588 KB Output isn't correct
29 Incorrect 1 ms 716 KB Output isn't correct
30 Incorrect 1 ms 716 KB Output isn't correct
31 Incorrect 1 ms 716 KB Output isn't correct
32 Incorrect 1 ms 716 KB Output isn't correct
33 Incorrect 4 ms 2892 KB Output isn't correct
34 Incorrect 4 ms 2988 KB Output isn't correct
35 Incorrect 6 ms 3276 KB Output isn't correct
36 Incorrect 5 ms 3404 KB Output isn't correct
37 Incorrect 5 ms 3404 KB Output isn't correct
38 Incorrect 7 ms 3812 KB Output isn't correct
39 Incorrect 6 ms 3788 KB Output isn't correct
40 Incorrect 5 ms 3788 KB Output isn't correct
41 Incorrect 9 ms 4188 KB Output isn't correct
42 Incorrect 7 ms 4172 KB Output isn't correct
43 Incorrect 8 ms 4172 KB Output isn't correct
44 Incorrect 11 ms 4556 KB Output isn't correct
45 Incorrect 9 ms 4556 KB Output isn't correct
46 Incorrect 8 ms 4568 KB Output isn't correct
47 Incorrect 14 ms 5068 KB Output isn't correct
48 Incorrect 10 ms 4904 KB Output isn't correct
49 Incorrect 10 ms 4940 KB Output isn't correct
50 Incorrect 17 ms 5452 KB Output isn't correct
51 Incorrect 11 ms 5324 KB Output isn't correct
52 Incorrect 11 ms 5324 KB Output isn't correct
53 Incorrect 19 ms 5896 KB Output isn't correct
54 Incorrect 13 ms 5804 KB Output isn't correct
55 Incorrect 15 ms 5780 KB Output isn't correct
56 Incorrect 25 ms 6320 KB Output isn't correct
57 Incorrect 15 ms 6092 KB Output isn't correct
58 Incorrect 14 ms 6092 KB Output isn't correct
59 Incorrect 25 ms 6852 KB Output isn't correct
60 Incorrect 17 ms 6476 KB Output isn't correct
61 Incorrect 16 ms 6572 KB Output isn't correct
62 Incorrect 29 ms 7252 KB Output isn't correct
63 Incorrect 25 ms 6708 KB Output isn't correct
64 Incorrect 24 ms 6604 KB Output isn't correct
65 Incorrect 24 ms 6604 KB Output isn't correct
66 Incorrect 25 ms 6720 KB Output isn't correct
67 Correct 24 ms 6548 KB Output is correct
68 Incorrect 26 ms 6636 KB Output isn't correct
69 Incorrect 30 ms 6596 KB Output isn't correct
70 Incorrect 26 ms 6640 KB Output isn't correct
71 Incorrect 28 ms 6636 KB Output isn't correct
72 Incorrect 35 ms 6736 KB Output isn't correct
73 Incorrect 30 ms 7740 KB Output isn't correct
74 Incorrect 26 ms 7240 KB Output isn't correct
75 Incorrect 27 ms 7700 KB Output isn't correct
76 Incorrect 25 ms 7292 KB Output isn't correct
77 Incorrect 27 ms 7780 KB Output isn't correct
78 Correct 27 ms 7080 KB Output is correct
79 Incorrect 26 ms 7104 KB Output isn't correct
80 Incorrect 26 ms 7072 KB Output isn't correct
81 Incorrect 25 ms 7108 KB Output isn't correct
82 Incorrect 26 ms 7080 KB Output isn't correct
83 Incorrect 26 ms 7004 KB Output isn't correct
84 Incorrect 26 ms 6992 KB Output isn't correct
85 Incorrect 24 ms 6992 KB Output isn't correct
86 Incorrect 24 ms 7088 KB Output isn't correct
87 Incorrect 26 ms 7040 KB Output isn't correct
88 Incorrect 24 ms 6904 KB Output isn't correct
89 Incorrect 28 ms 7036 KB Output isn't correct
90 Incorrect 25 ms 6908 KB Output isn't correct
91 Incorrect 23 ms 6908 KB Output isn't correct
92 Incorrect 24 ms 6956 KB Output isn't correct