Submission #960548

# Submission time Handle Problem Language Result Execution time Memory
960548 2024-04-10T15:44:36 Z LmaoLmao Mecho (IOI09_mecho) C++14
0 / 100
4 ms 856 KB
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
 
using ll = long long;
using ii = pair<int, int>;
 
const int N = 1e6+5;
const int INF = 1e9;

ll d[1000][1000],m[1000][1000],n,s;
char a[1000][1000];
ll dx[4]={1,0,0,-1};
ll dy[4]={0,1,-1,0};
ii pos,h;

bool bfs(int x) {
    queue<ii> q;
    q.push(pos);
    for(int i=0;i<n;i++) {
        for(int j=0;j<n;j++) {
            m[i][j]=0;
        }
    }
    while(!q.empty()) {
        ii u=q.front();
        q.pop();
        for(int i=0;i<4;i++) {
            ii v={u.fi+dx[i],u.se+dy[i]};
            if(v.fi<0 || v.fi>=n || v.se<0 || v.se>=n) continue;
            if(m[v.fi][v.se]==0 && a[v.fi][v.se]!='T' && 
            d[v.fi][v.se]-x>m[u.fi][u.se]+1 && a[v.fi][v.se]!='M') {
                m[v.fi][v.se]=m[u.fi][u.se]+1;
                q.push(v);
            }
        }
    }
    if(m[h.fi][h.se]>0) return 1; else return 0;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif
    queue<ii> q;
    cin >> n >> s;
    for(int i=0;i<n;i++) {
        for(int j=0;j<n;j++) {
            cin >> a[i][j];
            if(a[i][j]=='H') {
                q.push({i,j});
            }
            if(a[i][j]=='M') pos={i,j};
            if(a[i][j]=='D') h={i,j};
        }
    }
    while(!q.empty()) {
        ii u=q.front();
        q.pop();
        for(int i=0;i<4;i++) {
            ii v={u.fi+dx[i],u.se+dy[i]};
            if(v.fi<0 || v.fi>=n || v.se<0 || v.se>=n) continue;
            if(d[v.fi][v.se]==0 && a[v.fi][v.se]!='T' && a[v.fi][v.se]!='H') {
                d[v.fi][v.se]=d[u.fi][u.se]+s;
                q.push(v);
            }
        }
    }
    ll l=0,r=10000000000,ans=-1;
    while(l<=r) {
        int m=(l+r)/2;
        if(bfs(m)) {
            ans=m;
            l=m+1;
        }
        else {
            r=m-1;
        }
    }
    cout << ans/s;
    return 0;
}

Compilation message

mecho.cpp: In function 'int main()':
mecho.cpp:47:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |     freopen("in.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
mecho.cpp:48:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |     freopen("out.txt", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 600 KB Execution killed with signal 8
2 Runtime error 2 ms 600 KB Execution killed with signal 8
3 Runtime error 3 ms 604 KB Execution killed with signal 8
4 Runtime error 2 ms 604 KB Execution killed with signal 8
5 Runtime error 4 ms 624 KB Execution killed with signal 8
6 Runtime error 2 ms 604 KB Execution killed with signal 8
7 Runtime error 2 ms 604 KB Execution killed with signal 8
8 Runtime error 2 ms 604 KB Execution killed with signal 8
9 Runtime error 2 ms 604 KB Execution killed with signal 8
10 Runtime error 3 ms 604 KB Execution killed with signal 8
11 Runtime error 2 ms 604 KB Execution killed with signal 8
12 Runtime error 2 ms 600 KB Execution killed with signal 8
13 Runtime error 3 ms 580 KB Execution killed with signal 8
14 Runtime error 2 ms 600 KB Execution killed with signal 8
15 Runtime error 2 ms 604 KB Execution killed with signal 8
16 Runtime error 2 ms 604 KB Execution killed with signal 8
17 Runtime error 2 ms 604 KB Execution killed with signal 8
18 Runtime error 2 ms 604 KB Execution killed with signal 8
19 Runtime error 2 ms 604 KB Execution killed with signal 8
20 Runtime error 2 ms 604 KB Execution killed with signal 8
21 Runtime error 2 ms 604 KB Execution killed with signal 8
22 Runtime error 2 ms 604 KB Execution killed with signal 8
23 Runtime error 2 ms 604 KB Execution killed with signal 8
24 Runtime error 3 ms 604 KB Execution killed with signal 8
25 Runtime error 2 ms 604 KB Execution killed with signal 8
26 Runtime error 2 ms 604 KB Execution killed with signal 8
27 Runtime error 2 ms 604 KB Execution killed with signal 8
28 Runtime error 2 ms 604 KB Execution killed with signal 8
29 Runtime error 2 ms 604 KB Execution killed with signal 8
30 Runtime error 2 ms 604 KB Execution killed with signal 8
31 Runtime error 2 ms 604 KB Execution killed with signal 8
32 Runtime error 2 ms 604 KB Execution killed with signal 8
33 Runtime error 2 ms 604 KB Execution killed with signal 8
34 Runtime error 2 ms 604 KB Execution killed with signal 8
35 Runtime error 2 ms 604 KB Execution killed with signal 8
36 Runtime error 2 ms 604 KB Execution killed with signal 8
37 Runtime error 2 ms 536 KB Execution killed with signal 8
38 Runtime error 2 ms 604 KB Execution killed with signal 8
39 Runtime error 2 ms 604 KB Execution killed with signal 8
40 Runtime error 2 ms 604 KB Execution killed with signal 8
41 Runtime error 2 ms 604 KB Execution killed with signal 8
42 Runtime error 2 ms 600 KB Execution killed with signal 8
43 Runtime error 3 ms 604 KB Execution killed with signal 8
44 Runtime error 2 ms 604 KB Execution killed with signal 8
45 Runtime error 3 ms 508 KB Execution killed with signal 8
46 Runtime error 2 ms 600 KB Execution killed with signal 8
47 Runtime error 3 ms 604 KB Execution killed with signal 8
48 Runtime error 2 ms 604 KB Execution killed with signal 8
49 Runtime error 2 ms 604 KB Execution killed with signal 8
50 Runtime error 2 ms 604 KB Execution killed with signal 8
51 Runtime error 2 ms 604 KB Execution killed with signal 8
52 Runtime error 2 ms 604 KB Execution killed with signal 8
53 Runtime error 3 ms 604 KB Execution killed with signal 8
54 Runtime error 2 ms 604 KB Execution killed with signal 8
55 Runtime error 2 ms 604 KB Execution killed with signal 8
56 Runtime error 2 ms 604 KB Execution killed with signal 8
57 Runtime error 2 ms 604 KB Execution killed with signal 8
58 Runtime error 2 ms 604 KB Execution killed with signal 8
59 Runtime error 2 ms 604 KB Execution killed with signal 8
60 Runtime error 2 ms 604 KB Execution killed with signal 8
61 Runtime error 2 ms 604 KB Execution killed with signal 8
62 Runtime error 2 ms 604 KB Execution killed with signal 8
63 Runtime error 2 ms 856 KB Execution killed with signal 8
64 Runtime error 2 ms 604 KB Execution killed with signal 8
65 Runtime error 2 ms 536 KB Execution killed with signal 8
66 Runtime error 2 ms 604 KB Execution killed with signal 8
67 Runtime error 2 ms 604 KB Execution killed with signal 8
68 Runtime error 2 ms 612 KB Execution killed with signal 8
69 Runtime error 2 ms 612 KB Execution killed with signal 8
70 Runtime error 2 ms 616 KB Execution killed with signal 8
71 Runtime error 2 ms 604 KB Execution killed with signal 8
72 Runtime error 2 ms 604 KB Execution killed with signal 8
73 Runtime error 2 ms 600 KB Execution killed with signal 8
74 Runtime error 2 ms 616 KB Execution killed with signal 8
75 Runtime error 2 ms 608 KB Execution killed with signal 8
76 Runtime error 2 ms 604 KB Execution killed with signal 8
77 Runtime error 2 ms 548 KB Execution killed with signal 8
78 Runtime error 2 ms 604 KB Execution killed with signal 8
79 Runtime error 2 ms 536 KB Execution killed with signal 8
80 Runtime error 2 ms 616 KB Execution killed with signal 8
81 Runtime error 2 ms 616 KB Execution killed with signal 8
82 Runtime error 2 ms 604 KB Execution killed with signal 8
83 Runtime error 2 ms 608 KB Execution killed with signal 8
84 Runtime error 3 ms 604 KB Execution killed with signal 8
85 Runtime error 2 ms 612 KB Execution killed with signal 8
86 Runtime error 3 ms 616 KB Execution killed with signal 8
87 Runtime error 2 ms 616 KB Execution killed with signal 8
88 Runtime error 2 ms 616 KB Execution killed with signal 8
89 Runtime error 2 ms 612 KB Execution killed with signal 8
90 Runtime error 2 ms 612 KB Execution killed with signal 8
91 Runtime error 2 ms 604 KB Execution killed with signal 8
92 Runtime error 2 ms 616 KB Execution killed with signal 8