Submission #53513

# Submission time Handle Problem Language Result Execution time Memory
53513 2018-06-30T06:47:59 Z !?!?(#2015) Mecho (IOI09_mecho) C++11
16 / 100
1000 ms 196608 KB
#include<bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int N, S;
char arr[1024][1024];
int dist[1024][1024];
bool valid(int x, int y)
{
    return 0<=x&&x<N&&0<=y&&y<N;
}
bool can(int t)
{
    queue<tuple<int, int, int> > Q;
    for(int i=0; i<N; ++i)
        for(int j=0; j<N; ++j)
            if(arr[i][j] == 'M')
                Q.emplace(t*S, i, j);
    while(!Q.empty())
    {
        int di, x, y; tie(di, x, y) = Q.front(); Q.pop();
        if(arr[x][y] == 'D') return true;
        for(int d=0; d<4; ++d)
        {
            int nx = x+"1210"[d]-'1';
            int ny = y+"0121"[d]-'1';
            if(!valid(nx, ny)) continue;
            if(arr[nx][ny] != 'G' && arr[nx][ny] != 'D') continue;
            if(dist[nx][ny] <= di+1) continue;
            Q.emplace(di+1, nx, ny);
        }
    }
    return false;
}
void init()
{
    memset(dist, 0x3f, sizeof dist);
    queue<pair<int, int> > Q;
    for(int i=0; i<N; ++i)
        for(int j=0; j<N; ++j)
        {
            if(arr[i][j] == 'H')
            {
                Q.emplace(i, j);
                dist[i][j] = 0;
            }
        }
    while(!Q.empty())
    {
        int x, y; tie(x, y) = Q.front(); Q.pop();
        for(int d=0;d<4;++d)
        {
            int nx = x+"1210"[d] - '1';
            int ny = y+"0121"[d] - '1';
            if(!valid(nx, ny)) continue;
            if(arr[nx][ny] != 'G') continue;
            if(dist[nx][ny] != INF) continue;
            dist[nx][ny] = dist[x][y]+S;
            Q.emplace(nx, ny);
        }
    }
}
int main()
{
    scanf("%d%d", &N, &S);
    for(int i=0; i<N; ++i)
        scanf("%s", arr[i]);
    int lo = -1; //pos
    int hi = N*N; //impos
    init();
    while(lo+1!=hi)
    {
        int mi = (lo+hi)/2;
        if(can(mi)) lo = mi;
        else hi = mi;
    }
    printf("%d\n", lo);
}

Compilation message

mecho.cpp: In function 'int main()':
mecho.cpp:64:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &N, &S);
     ~~~~~^~~~~~~~~~~~~~~~
mecho.cpp:66:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%s", arr[i]);
         ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4472 KB Output is correct
2 Correct 6 ms 4472 KB Output is correct
3 Correct 5 ms 4660 KB Output is correct
4 Correct 6 ms 4696 KB Output is correct
5 Correct 7 ms 4716 KB Output is correct
6 Correct 9 ms 4920 KB Output is correct
7 Execution timed out 1031 ms 196608 KB Time limit exceeded
8 Correct 6 ms 196608 KB Output is correct
9 Correct 120 ms 196608 KB Output is correct
10 Correct 26 ms 196608 KB Output is correct
11 Correct 9 ms 196608 KB Output is correct
12 Incorrect 6 ms 196608 KB Output isn't correct
13 Execution timed out 1049 ms 196608 KB Time limit exceeded
14 Execution timed out 1037 ms 196608 KB Time limit exceeded
15 Execution timed out 1082 ms 196608 KB Time limit exceeded
16 Execution timed out 1078 ms 196608 KB Time limit exceeded
17 Execution timed out 1044 ms 196608 KB Time limit exceeded
18 Execution timed out 1050 ms 196608 KB Time limit exceeded
19 Execution timed out 1026 ms 196608 KB Time limit exceeded
20 Execution timed out 1020 ms 196608 KB Time limit exceeded
21 Execution timed out 1027 ms 196608 KB Time limit exceeded
22 Execution timed out 1020 ms 196608 KB Time limit exceeded
23 Execution timed out 1038 ms 196608 KB Time limit exceeded
24 Execution timed out 1026 ms 196608 KB Time limit exceeded
25 Execution timed out 1062 ms 196608 KB Time limit exceeded
26 Execution timed out 1049 ms 196608 KB Time limit exceeded
27 Execution timed out 1026 ms 196608 KB Time limit exceeded
28 Execution timed out 1067 ms 196608 KB Time limit exceeded
29 Execution timed out 1083 ms 196608 KB Time limit exceeded
30 Execution timed out 1079 ms 196608 KB Time limit exceeded
31 Execution timed out 1069 ms 196608 KB Time limit exceeded
32 Execution timed out 1020 ms 196608 KB Time limit exceeded
33 Execution timed out 1053 ms 196608 KB Time limit exceeded
34 Execution timed out 1028 ms 196608 KB Time limit exceeded
35 Execution timed out 1031 ms 196608 KB Time limit exceeded
36 Execution timed out 1076 ms 196608 KB Time limit exceeded
37 Execution timed out 1086 ms 196608 KB Time limit exceeded
38 Execution timed out 1045 ms 196608 KB Time limit exceeded
39 Execution timed out 1060 ms 196608 KB Time limit exceeded
40 Execution timed out 1087 ms 196608 KB Time limit exceeded
41 Execution timed out 1052 ms 196608 KB Time limit exceeded
42 Execution timed out 1065 ms 196608 KB Time limit exceeded
43 Execution timed out 1082 ms 196608 KB Time limit exceeded
44 Execution timed out 1026 ms 196608 KB Time limit exceeded
45 Execution timed out 1025 ms 196608 KB Time limit exceeded
46 Execution timed out 1022 ms 196608 KB Time limit exceeded
47 Execution timed out 1049 ms 196608 KB Time limit exceeded
48 Execution timed out 1061 ms 196608 KB Time limit exceeded
49 Execution timed out 1075 ms 196608 KB Time limit exceeded
50 Execution timed out 1044 ms 196608 KB Time limit exceeded
51 Execution timed out 1056 ms 196608 KB Time limit exceeded
52 Execution timed out 1059 ms 196608 KB Time limit exceeded
53 Execution timed out 1047 ms 196608 KB Time limit exceeded
54 Execution timed out 1049 ms 196608 KB Time limit exceeded
55 Execution timed out 1083 ms 196608 KB Time limit exceeded
56 Execution timed out 1071 ms 196608 KB Time limit exceeded
57 Execution timed out 1057 ms 196608 KB Time limit exceeded
58 Execution timed out 1028 ms 196608 KB Time limit exceeded
59 Execution timed out 1034 ms 196608 KB Time limit exceeded
60 Execution timed out 1029 ms 196608 KB Time limit exceeded
61 Execution timed out 1088 ms 196608 KB Time limit exceeded
62 Execution timed out 1018 ms 196608 KB Time limit exceeded
63 Execution timed out 1040 ms 196608 KB Time limit exceeded
64 Execution timed out 1049 ms 196608 KB Time limit exceeded
65 Execution timed out 1054 ms 196608 KB Time limit exceeded
66 Execution timed out 1028 ms 196608 KB Time limit exceeded
67 Execution timed out 1014 ms 196608 KB Time limit exceeded
68 Execution timed out 1026 ms 196608 KB Time limit exceeded
69 Execution timed out 1027 ms 196608 KB Time limit exceeded
70 Execution timed out 1030 ms 196608 KB Time limit exceeded
71 Execution timed out 1053 ms 196608 KB Time limit exceeded
72 Execution timed out 1034 ms 196608 KB Time limit exceeded
73 Execution timed out 1052 ms 196608 KB Time limit exceeded
74 Execution timed out 1039 ms 196608 KB Time limit exceeded
75 Execution timed out 1043 ms 196608 KB Time limit exceeded
76 Execution timed out 1046 ms 196608 KB Time limit exceeded
77 Execution timed out 1059 ms 196608 KB Time limit exceeded
78 Execution timed out 1031 ms 196608 KB Time limit exceeded
79 Execution timed out 1031 ms 196608 KB Time limit exceeded
80 Execution timed out 1083 ms 196608 KB Time limit exceeded
81 Execution timed out 1082 ms 196608 KB Time limit exceeded
82 Execution timed out 1031 ms 196608 KB Time limit exceeded
83 Execution timed out 1041 ms 196608 KB Time limit exceeded
84 Execution timed out 1043 ms 196608 KB Time limit exceeded
85 Execution timed out 1043 ms 196608 KB Time limit exceeded
86 Execution timed out 1082 ms 196608 KB Time limit exceeded
87 Execution timed out 1076 ms 196608 KB Time limit exceeded
88 Execution timed out 1052 ms 196608 KB Time limit exceeded
89 Execution timed out 1034 ms 196608 KB Time limit exceeded
90 Execution timed out 1054 ms 196608 KB Time limit exceeded
91 Execution timed out 1065 ms 196608 KB Time limit exceeded
92 Execution timed out 1018 ms 196608 KB Time limit exceeded