답안 #468611

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
468611 2021-08-29T03:12:01 Z Yuisuyuno Mecho (IOI09_mecho) C++14
35 / 100
214 ms 12276 KB
//Nguyen Huu Hoang Minh
#include <bits/stdc++.h>
#define sz(x) int(x.size())
#define all(x) x.begin(),x.end()
#define reset(x) memset(x, 0,sizeof(x))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define N 805
#define remain(x) if (x > MOD) x -= MOD
#define ii pair<int, int>
#define iiii pair< ii , ii >
#define viiii vector< iiii >
#define vi vector<int>
#define vii vector< ii >
#define bit(x, i) (((x) >> (i)) & 1)
#define Task "test"
#define int long long

using namespace std;

typedef long double ld;
const int inf = 1e10;
const int minf = -1e10;

int n, s;
char a[N][N];
ii M, D;
vector<ii> bee;

void readfile()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    if (fopen(Task".inp","r"))
    {
        freopen(Task".inp","r",stdin);
        //freopen(Task".out","w",stdout);
    }
    cin >> n >> s;
    for(int i=1; i<=n; i++){
        for(int j=1; j<=n; j++){
            cin >> a[i][j];
            if (a[i][j]=='M') M = ii(i,j);
            if (a[i][j]=='D') D = ii(i,j);
            if (a[i][j]=='H') bee.pb(ii(i,j));
        }
    }
}

int d[N][N];
int dm[N][N];
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
bool ok(int x, int y){
    if (1 <= x && x <= n && 1 <= y && y <= n) return true;
    return false;
}

void build_bee(){
    queue<ii> q;
    memset(d, -1, sizeof d);
    for(ii x : bee){
        d[x.fi][x.se]=0;
        q.push(ii(x.fi,x.se));
    }
    while (q.size()){
        int u = q.front().fi;
        int v = q.front().se;
        //cout << u << ' ' << v << ' ' << d[u][v] << endl;
        q.pop();
        for(int i=0; i<4; i++){
            int x = u + dx[i];
            int y = v + dy[i];
            if (d[x][y]==-1 && ok(x,y) && a[x][y]=='G'){
                d[x][y] = d[u][v] +1;
                q.push(ii(x,y));
            }
        }
    }
}

bool can_eat(int ti){
    queue<ii> q;
    memset(dm, -1, sizeof dm);
    dm[M.fi][M.se] = 0;
    q.push(ii(M.fi,M.se));
    while (q.size()){
        int u = q.front().fi;
        int v = q.front().se;
        q.pop();
        for(int i=0; i<4; i++){
            int x = u + dx[i];
            int y = v + dy[i];
            if (x==D.fi && y==D.se) return true;
            if (dm[x][y]==-1){
                dm[x][y] = dm[u][v] + 1;
                if (dm[x][y]/s + ti < d[x][y]){
                    q.push(ii(x,y));
                }
            }
        }
    }
    return false;
}

void proc()
{
    build_bee();
    int l = 0, r = 800, ans;
    while (r-l > 0){
        int mid = (l+r)/2;
        if (can_eat(mid)){
            l = mid+1;
            ans = mid;
        }
        else r = mid;
    }
    cout << ans;
}

signed main()
{
    readfile();
    proc();
    return 0;
}

Compilation message

mecho.cpp: In function 'void readfile()':
mecho.cpp:38:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         freopen(Task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 10444 KB Output is correct
2 Correct 8 ms 10444 KB Output is correct
3 Correct 8 ms 10388 KB Output is correct
4 Correct 8 ms 10468 KB Output is correct
5 Correct 8 ms 10476 KB Output is correct
6 Correct 8 ms 10444 KB Output is correct
7 Correct 100 ms 11936 KB Output is correct
8 Incorrect 8 ms 10376 KB Output isn't correct
9 Correct 8 ms 10444 KB Output is correct
10 Correct 8 ms 10444 KB Output is correct
11 Correct 8 ms 10444 KB Output is correct
12 Incorrect 8 ms 10444 KB Output isn't correct
13 Incorrect 8 ms 10444 KB Output isn't correct
14 Incorrect 8 ms 10444 KB Output isn't correct
15 Correct 9 ms 10484 KB Output is correct
16 Correct 8 ms 10412 KB Output is correct
17 Correct 8 ms 10444 KB Output is correct
18 Correct 8 ms 10488 KB Output is correct
19 Correct 8 ms 10444 KB Output is correct
20 Correct 8 ms 10440 KB Output is correct
21 Correct 7 ms 10444 KB Output is correct
22 Correct 8 ms 10444 KB Output is correct
23 Incorrect 8 ms 10444 KB Output isn't correct
24 Correct 8 ms 10512 KB Output is correct
25 Incorrect 8 ms 10516 KB Output isn't correct
26 Incorrect 8 ms 10420 KB Output isn't correct
27 Incorrect 9 ms 10444 KB Output isn't correct
28 Incorrect 8 ms 10444 KB Output isn't correct
29 Incorrect 8 ms 10444 KB Output isn't correct
30 Incorrect 8 ms 10444 KB Output isn't correct
31 Incorrect 7 ms 10444 KB Output isn't correct
32 Incorrect 8 ms 10480 KB Output isn't correct
33 Incorrect 11 ms 10828 KB Output isn't correct
34 Incorrect 12 ms 10872 KB Output isn't correct
35 Correct 30 ms 10844 KB Output is correct
36 Incorrect 12 ms 10828 KB Output isn't correct
37 Incorrect 13 ms 10924 KB Output isn't correct
38 Correct 40 ms 10952 KB Output is correct
39 Incorrect 15 ms 11024 KB Output isn't correct
40 Incorrect 16 ms 10956 KB Output isn't correct
41 Correct 48 ms 10912 KB Output is correct
42 Incorrect 14 ms 11072 KB Output isn't correct
43 Incorrect 15 ms 11084 KB Output isn't correct
44 Correct 60 ms 11104 KB Output is correct
45 Incorrect 17 ms 11196 KB Output isn't correct
46 Incorrect 16 ms 11192 KB Output isn't correct
47 Correct 68 ms 11212 KB Output is correct
48 Incorrect 18 ms 11224 KB Output isn't correct
49 Incorrect 17 ms 11212 KB Output isn't correct
50 Correct 92 ms 11288 KB Output is correct
51 Incorrect 20 ms 11320 KB Output isn't correct
52 Incorrect 23 ms 11324 KB Output isn't correct
53 Correct 96 ms 11292 KB Output is correct
54 Incorrect 21 ms 11468 KB Output isn't correct
55 Incorrect 21 ms 11508 KB Output isn't correct
56 Correct 115 ms 11560 KB Output is correct
57 Incorrect 23 ms 11596 KB Output isn't correct
58 Incorrect 23 ms 11540 KB Output isn't correct
59 Correct 130 ms 11608 KB Output is correct
60 Incorrect 25 ms 11652 KB Output isn't correct
61 Incorrect 25 ms 11624 KB Output isn't correct
62 Correct 154 ms 11724 KB Output is correct
63 Correct 131 ms 11644 KB Output is correct
64 Incorrect 214 ms 11740 KB Output isn't correct
65 Correct 170 ms 11732 KB Output is correct
66 Correct 183 ms 11660 KB Output is correct
67 Incorrect 145 ms 11716 KB Output isn't correct
68 Correct 64 ms 11720 KB Output is correct
69 Correct 53 ms 11752 KB Output is correct
70 Correct 48 ms 11716 KB Output is correct
71 Correct 51 ms 11708 KB Output is correct
72 Incorrect 90 ms 11784 KB Output isn't correct
73 Incorrect 81 ms 12228 KB Output isn't correct
74 Correct 66 ms 12196 KB Output is correct
75 Correct 77 ms 12252 KB Output is correct
76 Correct 72 ms 12228 KB Output is correct
77 Correct 74 ms 12276 KB Output is correct
78 Incorrect 92 ms 12176 KB Output isn't correct
79 Correct 65 ms 12184 KB Output is correct
80 Correct 77 ms 12188 KB Output is correct
81 Correct 81 ms 12196 KB Output is correct
82 Correct 66 ms 12152 KB Output is correct
83 Correct 93 ms 12096 KB Output is correct
84 Correct 82 ms 12100 KB Output is correct
85 Correct 78 ms 12096 KB Output is correct
86 Correct 86 ms 12168 KB Output is correct
87 Correct 83 ms 12164 KB Output is correct
88 Correct 91 ms 12052 KB Output is correct
89 Correct 91 ms 12056 KB Output is correct
90 Correct 96 ms 11980 KB Output is correct
91 Correct 93 ms 11980 KB Output is correct
92 Correct 85 ms 11960 KB Output is correct