답안 #54414

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
54414 2018-07-03T11:29:18 Z upsolving(#1416) Mecho (IOI09_mecho) C++11
84 / 100
231 ms 37684 KB
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef pair<pii,int> piii;
int dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
int pre[1000][1000];
char mark[1000][1000];
int homex,homey;
int s,sx,sy,N;
bool test(int time)
{
    bool reach[1005][1005];
    memset(reach,0,sizeof(reach));
    if(time * s > pre[homex][homey]) return false;
    queue<piii> q;
    q.push(make_pair(make_pair(sx,sy),time*s));
    reach[sx][sy]=1;
    while(!q.empty())
    {
        int x=q.front().first.first;
        int y=q.front().first.second;
        int dis=q.front().second;
        q.pop();
        for(int c=0;c<4;c++)
        {
            int cx=x+dx[c],cy=y+dy[c];
            if(cx==homex && cy==homey) return true;
            if(cx<0 || cx>=N || cy<0 || cy>=N || pre[cx][cy]<=dis+1 || mark[cx][cy]=='T' || reach[cx][cy]) continue;
            reach[cx][cy]=true;
            q.push(make_pair(make_pair(cx,cy),dis+1));
        }
    }
    return false;
}
int main()
{
    bool reach[1005][1005];
    memset(reach,0,sizeof(reach));
    memset(pre,-1,sizeof(pre));
    scanf("%d %d",&N,&s);
    queue<pii> que;
    for(int i=0;i<N;i++)scanf("%s",mark[i]);
    for(int i=0;i<N;i++){
            for(int j=0;j<N;j++)
            {
                if(mark[i][j]=='M') sx=i,sy=j;
                if(mark[i][j]=='D') homex=i,homey=j;
                if(mark[i][j]=='H') que.push(make_pair(i,j)),pre[i][j]=0;
            }
    }
    pre[homex][homey]=N*N*s;
    while(!que.empty())
    {
        int x=que.front().first;
        int y=que.front().second;
        int dis=pre[x][y];
        que.pop();
        for(int c=0;c<4;c++)
        {
            int cx=x+dx[c],cy=y+dy[c];
            if(cx<0 || cx>=N || cy<0 || cy>=N || pre[cx][cy]!=-1 || mark[cx][cy]!='G') continue;
            pre[cx][cy]=dis+s;
            que.push(make_pair(cx,cy));
        }
    }
    int low=0,high=N*N*2,ans=-1;
    for(;low<high;)
    {
        int mid=(low+high)/2;
        if(test(mid)) ans=max(ans,mid),low=mid+1;
        else high=mid;
    }
    return !printf("%d",ans);
}

Compilation message

mecho.cpp: In function 'int main()':
mecho.cpp:40: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:42:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=0;i<N;i++)scanf("%s",mark[i]);
                         ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 6264 KB Output is correct
2 Correct 8 ms 6364 KB Output is correct
3 Correct 8 ms 6364 KB Output is correct
4 Correct 8 ms 6364 KB Output is correct
5 Correct 8 ms 6364 KB Output is correct
6 Correct 8 ms 6416 KB Output is correct
7 Correct 126 ms 8088 KB Output is correct
8 Correct 7 ms 8088 KB Output is correct
9 Correct 7 ms 8088 KB Output is correct
10 Correct 7 ms 8088 KB Output is correct
11 Correct 7 ms 8088 KB Output is correct
12 Incorrect 9 ms 8088 KB Output isn't correct
13 Incorrect 8 ms 8088 KB Output isn't correct
14 Correct 9 ms 8088 KB Output is correct
15 Correct 8 ms 8088 KB Output is correct
16 Correct 7 ms 8088 KB Output is correct
17 Correct 9 ms 8088 KB Output is correct
18 Correct 7 ms 8088 KB Output is correct
19 Correct 8 ms 8088 KB Output is correct
20 Correct 9 ms 8088 KB Output is correct
21 Correct 8 ms 8088 KB Output is correct
22 Correct 10 ms 8088 KB Output is correct
23 Correct 9 ms 8088 KB Output is correct
24 Correct 9 ms 8088 KB Output is correct
25 Correct 7 ms 8088 KB Output is correct
26 Correct 7 ms 8088 KB Output is correct
27 Correct 9 ms 8088 KB Output is correct
28 Correct 8 ms 8088 KB Output is correct
29 Correct 7 ms 8088 KB Output is correct
30 Correct 7 ms 8088 KB Output is correct
31 Correct 9 ms 8088 KB Output is correct
32 Correct 8 ms 8088 KB Output is correct
33 Correct 10 ms 8088 KB Output is correct
34 Correct 10 ms 8088 KB Output is correct
35 Correct 29 ms 8136 KB Output is correct
36 Correct 10 ms 8336 KB Output is correct
37 Correct 11 ms 8496 KB Output is correct
38 Correct 40 ms 8684 KB Output is correct
39 Correct 11 ms 8816 KB Output is correct
40 Correct 11 ms 9016 KB Output is correct
41 Correct 46 ms 9216 KB Output is correct
42 Correct 11 ms 9544 KB Output is correct
43 Correct 12 ms 9796 KB Output is correct
44 Correct 54 ms 10088 KB Output is correct
45 Correct 13 ms 10368 KB Output is correct
46 Correct 13 ms 10728 KB Output is correct
47 Correct 73 ms 11136 KB Output is correct
48 Correct 14 ms 11432 KB Output is correct
49 Correct 14 ms 11788 KB Output is correct
50 Correct 74 ms 12144 KB Output is correct
51 Correct 18 ms 12628 KB Output is correct
52 Correct 18 ms 13044 KB Output is correct
53 Correct 112 ms 13528 KB Output is correct
54 Correct 16 ms 14004 KB Output is correct
55 Correct 16 ms 14484 KB Output is correct
56 Correct 114 ms 15056 KB Output is correct
57 Correct 18 ms 15448 KB Output is correct
58 Correct 18 ms 16000 KB Output is correct
59 Correct 133 ms 16680 KB Output is correct
60 Correct 19 ms 17232 KB Output is correct
61 Correct 18 ms 17860 KB Output is correct
62 Correct 159 ms 18624 KB Output is correct
63 Correct 125 ms 19372 KB Output is correct
64 Correct 231 ms 19888 KB Output is correct
65 Correct 198 ms 20516 KB Output is correct
66 Correct 140 ms 21144 KB Output is correct
67 Correct 144 ms 21772 KB Output is correct
68 Correct 64 ms 22400 KB Output is correct
69 Correct 46 ms 23028 KB Output is correct
70 Correct 46 ms 23672 KB Output is correct
71 Correct 40 ms 24380 KB Output is correct
72 Incorrect 81 ms 24928 KB Output isn't correct
73 Incorrect 101 ms 25740 KB Output isn't correct
74 Correct 66 ms 26440 KB Output is correct
75 Correct 95 ms 27068 KB Output is correct
76 Correct 102 ms 27756 KB Output is correct
77 Correct 102 ms 28340 KB Output is correct
78 Correct 98 ms 28840 KB Output is correct
79 Correct 58 ms 29612 KB Output is correct
80 Correct 89 ms 30104 KB Output is correct
81 Correct 92 ms 30868 KB Output is correct
82 Correct 69 ms 31372 KB Output is correct
83 Correct 104 ms 32168 KB Output is correct
84 Correct 84 ms 32656 KB Output is correct
85 Correct 86 ms 33284 KB Output is correct
86 Correct 88 ms 33912 KB Output is correct
87 Correct 87 ms 34540 KB Output is correct
88 Correct 116 ms 35264 KB Output is correct
89 Correct 124 ms 35768 KB Output is correct
90 Correct 98 ms 36492 KB Output is correct
91 Correct 109 ms 37056 KB Output is correct
92 Correct 97 ms 37684 KB Output is correct