답안 #500024

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
500024 2021-12-30T09:37:45 Z Nartifact Mecho (IOI09_mecho) C++14
8 / 100
146 ms 7904 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;
    memset(cx, 0, sizeof cx);
    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:83:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   83 |         int mid = l + r >> 1;
      |                   ~~^~~
mecho.cpp: At global scope:
mecho.cpp:101:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  101 | main ()
      | ^~~~
mecho.cpp: In function 'int main()':
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 ".inp", "r", stdin);
      |   ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
mecho.cpp:107:11: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  107 |   freopen (task ".out", "w", stdout);
      |   ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 1100 KB Output isn't correct
2 Incorrect 1 ms 1100 KB Output isn't correct
3 Incorrect 1 ms 1100 KB Output isn't correct
4 Incorrect 1 ms 1100 KB Output isn't correct
5 Incorrect 1 ms 1100 KB Output isn't correct
6 Incorrect 1 ms 1100 KB Output isn't correct
7 Correct 114 ms 7556 KB Output is correct
8 Incorrect 1 ms 1100 KB Output isn't correct
9 Incorrect 1 ms 1100 KB Output isn't correct
10 Incorrect 1 ms 1100 KB Output isn't correct
11 Incorrect 1 ms 1100 KB Output isn't correct
12 Incorrect 1 ms 1340 KB Output isn't correct
13 Incorrect 1 ms 1356 KB Output isn't correct
14 Correct 1 ms 1356 KB Output is correct
15 Incorrect 1 ms 1100 KB Output isn't correct
16 Incorrect 1 ms 1100 KB Output isn't correct
17 Incorrect 1 ms 1100 KB Output isn't correct
18 Incorrect 1 ms 1100 KB Output isn't correct
19 Incorrect 1 ms 1228 KB Output isn't correct
20 Incorrect 1 ms 1228 KB Output isn't correct
21 Incorrect 1 ms 1228 KB Output isn't correct
22 Incorrect 1 ms 1228 KB Output isn't correct
23 Incorrect 1 ms 1356 KB Output isn't correct
24 Incorrect 1 ms 1356 KB Output isn't correct
25 Incorrect 1 ms 1356 KB Output isn't correct
26 Incorrect 1 ms 1356 KB Output isn't correct
27 Incorrect 1 ms 1356 KB Output isn't correct
28 Incorrect 1 ms 1356 KB Output isn't correct
29 Incorrect 1 ms 1356 KB Output isn't correct
30 Incorrect 2 ms 1356 KB Output isn't correct
31 Incorrect 1 ms 1484 KB Output isn't correct
32 Incorrect 1 ms 1484 KB Output isn't correct
33 Incorrect 5 ms 3660 KB Output isn't correct
34 Incorrect 5 ms 3660 KB Output isn't correct
35 Incorrect 19 ms 3768 KB Output isn't correct
36 Incorrect 7 ms 4172 KB Output isn't correct
37 Incorrect 5 ms 4216 KB Output isn't correct
38 Incorrect 26 ms 4236 KB Output isn't correct
39 Incorrect 7 ms 4604 KB Output isn't correct
40 Incorrect 7 ms 4556 KB Output isn't correct
41 Incorrect 32 ms 4624 KB Output isn't correct
42 Incorrect 8 ms 4940 KB Output isn't correct
43 Incorrect 7 ms 5008 KB Output isn't correct
44 Incorrect 39 ms 4940 KB Output isn't correct
45 Incorrect 9 ms 5312 KB Output isn't correct
46 Incorrect 11 ms 5336 KB Output isn't correct
47 Incorrect 64 ms 5404 KB Output isn't correct
48 Incorrect 13 ms 5788 KB Output isn't correct
49 Incorrect 11 ms 5680 KB Output isn't correct
50 Incorrect 54 ms 5680 KB Output isn't correct
51 Incorrect 12 ms 6184 KB Output isn't correct
52 Incorrect 11 ms 6100 KB Output isn't correct
53 Incorrect 65 ms 6192 KB Output isn't correct
54 Incorrect 14 ms 6568 KB Output isn't correct
55 Incorrect 14 ms 6560 KB Output isn't correct
56 Incorrect 84 ms 6564 KB Output isn't correct
57 Incorrect 17 ms 6892 KB Output isn't correct
58 Incorrect 18 ms 6956 KB Output isn't correct
59 Incorrect 96 ms 6968 KB Output isn't correct
60 Incorrect 18 ms 7244 KB Output isn't correct
61 Incorrect 16 ms 7312 KB Output isn't correct
62 Incorrect 109 ms 7244 KB Output isn't correct
63 Incorrect 105 ms 7340 KB Output isn't correct
64 Incorrect 146 ms 7356 KB Output isn't correct
65 Incorrect 139 ms 7244 KB Output isn't correct
66 Incorrect 127 ms 7344 KB Output isn't correct
67 Correct 106 ms 7236 KB Output is correct
68 Incorrect 48 ms 7388 KB Output isn't correct
69 Incorrect 47 ms 7372 KB Output isn't correct
70 Incorrect 43 ms 7368 KB Output isn't correct
71 Incorrect 29 ms 7372 KB Output isn't correct
72 Incorrect 29 ms 7396 KB Output isn't correct
73 Incorrect 32 ms 7892 KB Output isn't correct
74 Incorrect 76 ms 7860 KB Output isn't correct
75 Incorrect 61 ms 7884 KB Output isn't correct
76 Incorrect 57 ms 7904 KB Output isn't correct
77 Incorrect 56 ms 7888 KB Output isn't correct
78 Correct 71 ms 7876 KB Output is correct
79 Incorrect 43 ms 7804 KB Output isn't correct
80 Incorrect 56 ms 7828 KB Output isn't correct
81 Incorrect 75 ms 7876 KB Output isn't correct
82 Incorrect 54 ms 7724 KB Output isn't correct
83 Incorrect 70 ms 7752 KB Output isn't correct
84 Incorrect 63 ms 7752 KB Output isn't correct
85 Incorrect 67 ms 7760 KB Output isn't correct
86 Incorrect 86 ms 7752 KB Output isn't correct
87 Incorrect 70 ms 7752 KB Output isn't correct
88 Incorrect 70 ms 7660 KB Output isn't correct
89 Incorrect 71 ms 7656 KB Output isn't correct
90 Incorrect 86 ms 7656 KB Output isn't correct
91 Incorrect 118 ms 7656 KB Output isn't correct
92 Incorrect 104 ms 7656 KB Output isn't correct