답안 #57580

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
57580 2018-07-15T09:25:40 Z Bodo171 Mecho (IOI09_mecho) C++14
68 / 100
336 ms 10748 KB
#include <iostream>
#include <fstream>

using namespace std;
const int nmax=805;
int d1[]={-1,0,1,0};
int d2[]={0,-1,0,1};
int d[nmax][nmax],a[nmax][nmax];
string s;
pair<int,int> q[nmax*nmax];
int p,u,n,m,i,j,li,ci,lf,cf,l1,l2,c1,c2,S,ans;
bool ok(int X,int Y)
{
    return (X>=1&&Y>=1&&X<=n&&Y<=n);
}
void bfs()
{
    p=1;
    for(i=1;i<=n;i++)
        for(j=1;j<=n;j++)
           if(a[i][j]==0)
             q[++u]={i,j};
    for(p=1;p<=u;p++)
    {
        li=q[p].first;ci=q[p].second;
        for(i=0;i<4;i++)
        {
            lf=li+d1[i];cf=ci+d2[i];
            if(ok(lf,cf)&&a[li][ci]+1<a[lf][cf])
            {
                a[lf][cf]=a[li][ci]+1;
                q[++u]={lf,cf};
            }
        }
    }

}
bool check(int val)
{
    for(i=1;i<=n;i++)
        for(j=1;j<=n;j++)
           if(d[i][j]!=-1)
              d[i][j]=0;
    d[l1][c1]=1;
    q[p=u=1]={l1,c1};
    for(p=1;p<=u;p++)
    {
        li=q[p].first;ci=q[p].second;
        if((d[li][ci]-1)/S+val>=a[li][ci]) continue;
        if(li==l2&&ci==c2) return 1;
        for(i=0;i<4;i++)
        {
            lf=li+d1[i];cf=ci+d2[i];
            if(ok(lf,cf)&&(!d[lf][cf]))
            {
                d[lf][cf]=d[li][ci]+1;
                q[++u]={lf,cf};
            }
        }
    }
    return 0;
}
int main()
{
    //freopen("data.in","r",stdin);
    cin>>n>>S;
    for(i=0;i<=n+1;i++)
        for(j=0;j<=n+1;j++)
           a[i][j]=(1<<30);
    for(i=1;i<=n;i++)
    {
        cin>>s;
        for(j=0;j<n;j++)
        {
            if(s[j]=='T') d[i][j+1]=a[i][j+1]=-1;
            if(s[j]=='M') l1=i,c1=j+1;
            if(s[j]=='D') l2=i,c2=j+1;
            if(s[j]=='H') a[i][j+1]=0;
        }
    }
    bfs();
   for(int pu=20;pu>=0;pu--)
        if(check(ans+(1<<pu)))
           ans+=(1<<pu);
    cout<<ans;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 3 ms 488 KB Output isn't correct
3 Correct 2 ms 532 KB Output is correct
4 Incorrect 2 ms 532 KB Output isn't correct
5 Correct 2 ms 708 KB Output is correct
6 Incorrect 3 ms 708 KB Output isn't correct
7 Incorrect 151 ms 10676 KB Output isn't correct
8 Incorrect 2 ms 10676 KB Output isn't correct
9 Correct 2 ms 10676 KB Output is correct
10 Correct 3 ms 10676 KB Output is correct
11 Correct 3 ms 10676 KB Output is correct
12 Incorrect 3 ms 10676 KB Output isn't correct
13 Correct 3 ms 10676 KB Output is correct
14 Incorrect 3 ms 10676 KB Output isn't correct
15 Correct 3 ms 10676 KB Output is correct
16 Correct 2 ms 10676 KB Output is correct
17 Correct 2 ms 10676 KB Output is correct
18 Correct 2 ms 10676 KB Output is correct
19 Correct 2 ms 10676 KB Output is correct
20 Correct 3 ms 10676 KB Output is correct
21 Correct 2 ms 10676 KB Output is correct
22 Correct 3 ms 10676 KB Output is correct
23 Correct 2 ms 10676 KB Output is correct
24 Correct 3 ms 10676 KB Output is correct
25 Correct 3 ms 10676 KB Output is correct
26 Correct 2 ms 10676 KB Output is correct
27 Correct 4 ms 10676 KB Output is correct
28 Correct 4 ms 10676 KB Output is correct
29 Correct 4 ms 10676 KB Output is correct
30 Correct 3 ms 10676 KB Output is correct
31 Correct 3 ms 10676 KB Output is correct
32 Correct 3 ms 10676 KB Output is correct
33 Correct 13 ms 10676 KB Output is correct
34 Correct 13 ms 10676 KB Output is correct
35 Correct 41 ms 10676 KB Output is correct
36 Correct 24 ms 10676 KB Output is correct
37 Correct 16 ms 10676 KB Output is correct
38 Correct 38 ms 10676 KB Output is correct
39 Correct 18 ms 10676 KB Output is correct
40 Correct 18 ms 10676 KB Output is correct
41 Correct 88 ms 10676 KB Output is correct
42 Correct 27 ms 10676 KB Output is correct
43 Correct 23 ms 10676 KB Output is correct
44 Correct 81 ms 10676 KB Output is correct
45 Correct 32 ms 10676 KB Output is correct
46 Correct 40 ms 10676 KB Output is correct
47 Correct 111 ms 10676 KB Output is correct
48 Correct 35 ms 10676 KB Output is correct
49 Correct 29 ms 10676 KB Output is correct
50 Correct 107 ms 10676 KB Output is correct
51 Correct 33 ms 10676 KB Output is correct
52 Correct 37 ms 10676 KB Output is correct
53 Correct 227 ms 10676 KB Output is correct
54 Correct 43 ms 10676 KB Output is correct
55 Correct 46 ms 10676 KB Output is correct
56 Correct 139 ms 10676 KB Output is correct
57 Correct 46 ms 10676 KB Output is correct
58 Correct 47 ms 10676 KB Output is correct
59 Correct 234 ms 10676 KB Output is correct
60 Correct 73 ms 10676 KB Output is correct
61 Correct 59 ms 10676 KB Output is correct
62 Correct 249 ms 10676 KB Output is correct
63 Correct 252 ms 10676 KB Output is correct
64 Correct 336 ms 10676 KB Output is correct
65 Correct 330 ms 10676 KB Output is correct
66 Correct 294 ms 10676 KB Output is correct
67 Incorrect 265 ms 10676 KB Output isn't correct
68 Correct 194 ms 10676 KB Output is correct
69 Correct 172 ms 10676 KB Output is correct
70 Correct 127 ms 10676 KB Output is correct
71 Correct 174 ms 10676 KB Output is correct
72 Correct 133 ms 10676 KB Output is correct
73 Correct 99 ms 10676 KB Output is correct
74 Correct 122 ms 10748 KB Output is correct
75 Correct 113 ms 10748 KB Output is correct
76 Correct 108 ms 10748 KB Output is correct
77 Correct 181 ms 10748 KB Output is correct
78 Incorrect 185 ms 10748 KB Output isn't correct
79 Correct 109 ms 10748 KB Output is correct
80 Correct 132 ms 10748 KB Output is correct
81 Correct 117 ms 10748 KB Output is correct
82 Correct 144 ms 10748 KB Output is correct
83 Correct 184 ms 10748 KB Output is correct
84 Correct 128 ms 10748 KB Output is correct
85 Correct 124 ms 10748 KB Output is correct
86 Correct 164 ms 10748 KB Output is correct
87 Correct 155 ms 10748 KB Output is correct
88 Correct 160 ms 10748 KB Output is correct
89 Correct 167 ms 10748 KB Output is correct
90 Correct 182 ms 10748 KB Output is correct
91 Correct 178 ms 10748 KB Output is correct
92 Correct 158 ms 10748 KB Output is correct