# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1106356 |
2024-10-30T04:41:04 Z |
lufychop |
Mecho (IOI09_mecho) |
C++14 |
|
115 ms |
23900 KB |
#include <bits/stdc++.h>
using namespace std;
bool ch=false;
long long n,s,si,sj,ei,ej;
long long a[1000][1000];
long long b[1000][1000];
long long c[1000][1000];
long long x[4]={0,0,-1,1};
long long y[4]={-1,1,0,0};
bool check(long long t)
{
queue<pair<pair<long long,long long>,pair<long long,long long> > > h;
h.push({{0,t},{si,sj}});
c[si][sj]=t;
while(!h.empty())
{
long long t0=h.front().first.first;
long long t1=h.front().first.second;
long long t2=h.front().second.first;
long long t3=h.front().second.second;
h.pop();
if(t2==ei && t3==ej)
{
while(!h.empty())
{
h.pop();
}
return true;
}
for(int i=0;i<4;i++)
{
if(-1<a[t2+x[i]][t3+y[i]] && a[t2+x[i]][t3+y[i]]<=t1+(t0+1)/s)
{
continue;
}
if(c[t2+x[i]][t3+y[i]]>t1+(t0+1)/s)
{
c[t2+x[i]][t3+y[i]]=t1+(t0+1)/s;
h.push({{(t0+1)%s,t1+(t0+1)/s},{t2+x[i],t3+y[i]}});
}
}
}
return false;
}
int main(void)
{
queue<pair<long long,pair<long long,long long> > > h;
cin>>n>>s;
for(int i=0;i<=n+100;i++)
{
for(int j=0;j<=n+100;j++)
{
a[i][j]=-1;
b[i][j]=-1;
}
}
for(int i=1;i<=n;i++)
{
string tt;
cin>>tt;
for(int j=1;j<=n;j++)
{
if(tt[j-1]=='T')
{
a[i][j]=-1;
b[i][j]=-1;
}
else
{
a[i][j]=INT_MAX;
b[i][j]=INT_MAX;
}
if(tt[j-1]=='M')
{
si=i;
sj=j;
}
else if(tt[j-1]=='D')
{
a[i][j]=-1;
ei=i;
ej=j;
}
else if(tt[j-1]=='H')
{
h.push({0,{i,j}});
a[i][j]=0;
}
}
}
while(!h.empty())
{
long long t1=h.front().first;
long long t2=h.front().second.first;
long long t3=h.front().second.second;
h.pop();
for(int i=0;i<4;i++)
{
if(a[t2+x[i]][t3+y[i]]>t1+1)
{
a[t2+x[i]][t3+y[i]]=t1+1;
h.push({t1+1,{t2+x[i],t3+y[i]}});
}
}
}
// for(int i=0;i<=n;i++)
// {
// for(int j=0;j<=n;j++)
// {
// if(a[i][j]==INT_MAX)
// {
// cout<<"-1 ";
// continue;
// }
// cout<<a[i][j]<<" ";
// }
// cout<<"\n";
// }
long long l=0,r=1000000;
while(l<=r)
{
long long mid=(l+r)/2;
for(int i=0;i<n+100;i++)
{
for(int j=0;j<n+100;j++)
{
c[i][j]=b[i][j];
}
}
if(check(mid))
{
l=mid+1;
ch=true;
}
else
{
r=mid-1;
}
}
// for(int i=0;i<=n;i++)
// {
// for(int j=0;j<=n;j++)
// {
// if(c[i][j]==INT_MAX)
// {
// cout<<"-1 ";
// continue;
// }
// cout<<c[i][j]<<" ";
// }
// cout<<"\n";
// }
if(ch)
{
cout<<-1;
}
else
{
cout<<-1;
}
return 0;
}
/*
7 3
TTTTTTT
TGGGGGT
TGGGGGT
MGGGGGD
TGGGGGT
TGGGGGT
THHHHHT
TTTTTTT
T55555T
T44444T
M33333D
T22222T
T11111T
THHHHHT
TTTTTTT
T55555T
T44444T
M111222
T22222T
T11111T
THHHHHT
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
8528 KB |
Output isn't correct |
2 |
Incorrect |
2 ms |
8676 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
8528 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
8528 KB |
Output isn't correct |
5 |
Incorrect |
1 ms |
8528 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
8528 KB |
Output isn't correct |
7 |
Incorrect |
61 ms |
23376 KB |
Output isn't correct |
8 |
Correct |
2 ms |
8528 KB |
Output is correct |
9 |
Incorrect |
1 ms |
8528 KB |
Output isn't correct |
10 |
Incorrect |
1 ms |
8528 KB |
Output isn't correct |
11 |
Incorrect |
2 ms |
8528 KB |
Output isn't correct |
12 |
Incorrect |
2 ms |
10676 KB |
Output isn't correct |
13 |
Incorrect |
2 ms |
10832 KB |
Output isn't correct |
14 |
Correct |
2 ms |
10832 KB |
Output is correct |
15 |
Incorrect |
2 ms |
11000 KB |
Output isn't correct |
16 |
Incorrect |
2 ms |
10576 KB |
Output isn't correct |
17 |
Incorrect |
2 ms |
10744 KB |
Output isn't correct |
18 |
Incorrect |
2 ms |
10576 KB |
Output isn't correct |
19 |
Incorrect |
2 ms |
10576 KB |
Output isn't correct |
20 |
Incorrect |
2 ms |
10576 KB |
Output isn't correct |
21 |
Incorrect |
2 ms |
10832 KB |
Output isn't correct |
22 |
Incorrect |
2 ms |
10576 KB |
Output isn't correct |
23 |
Incorrect |
2 ms |
10576 KB |
Output isn't correct |
24 |
Incorrect |
2 ms |
10748 KB |
Output isn't correct |
25 |
Incorrect |
2 ms |
10576 KB |
Output isn't correct |
26 |
Incorrect |
2 ms |
10576 KB |
Output isn't correct |
27 |
Incorrect |
2 ms |
10576 KB |
Output isn't correct |
28 |
Incorrect |
2 ms |
11000 KB |
Output isn't correct |
29 |
Incorrect |
2 ms |
10832 KB |
Output isn't correct |
30 |
Incorrect |
2 ms |
10832 KB |
Output isn't correct |
31 |
Incorrect |
2 ms |
10832 KB |
Output isn't correct |
32 |
Incorrect |
2 ms |
10692 KB |
Output isn't correct |
33 |
Incorrect |
7 ms |
16976 KB |
Output isn't correct |
34 |
Incorrect |
7 ms |
16976 KB |
Output isn't correct |
35 |
Incorrect |
18 ms |
16988 KB |
Output isn't correct |
36 |
Incorrect |
10 ms |
16976 KB |
Output isn't correct |
37 |
Incorrect |
8 ms |
16976 KB |
Output isn't correct |
38 |
Incorrect |
21 ms |
16976 KB |
Output isn't correct |
39 |
Incorrect |
10 ms |
19024 KB |
Output isn't correct |
40 |
Incorrect |
9 ms |
19024 KB |
Output isn't correct |
41 |
Incorrect |
26 ms |
19024 KB |
Output isn't correct |
42 |
Incorrect |
11 ms |
21072 KB |
Output isn't correct |
43 |
Incorrect |
11 ms |
20956 KB |
Output isn't correct |
44 |
Incorrect |
34 ms |
21072 KB |
Output isn't correct |
45 |
Incorrect |
13 ms |
23120 KB |
Output isn't correct |
46 |
Incorrect |
12 ms |
23192 KB |
Output isn't correct |
47 |
Incorrect |
40 ms |
23120 KB |
Output isn't correct |
48 |
Incorrect |
16 ms |
23120 KB |
Output isn't correct |
49 |
Incorrect |
15 ms |
23120 KB |
Output isn't correct |
50 |
Incorrect |
47 ms |
23120 KB |
Output isn't correct |
51 |
Incorrect |
16 ms |
23120 KB |
Output isn't correct |
52 |
Incorrect |
16 ms |
23120 KB |
Output isn't correct |
53 |
Incorrect |
61 ms |
23136 KB |
Output isn't correct |
54 |
Incorrect |
21 ms |
23288 KB |
Output isn't correct |
55 |
Incorrect |
17 ms |
23120 KB |
Output isn't correct |
56 |
Incorrect |
63 ms |
23204 KB |
Output isn't correct |
57 |
Incorrect |
20 ms |
23120 KB |
Output isn't correct |
58 |
Incorrect |
19 ms |
23200 KB |
Output isn't correct |
59 |
Incorrect |
73 ms |
23208 KB |
Output isn't correct |
60 |
Incorrect |
21 ms |
23120 KB |
Output isn't correct |
61 |
Incorrect |
21 ms |
23120 KB |
Output isn't correct |
62 |
Incorrect |
81 ms |
23132 KB |
Output isn't correct |
63 |
Incorrect |
80 ms |
23120 KB |
Output isn't correct |
64 |
Incorrect |
115 ms |
23132 KB |
Output isn't correct |
65 |
Incorrect |
107 ms |
23120 KB |
Output isn't correct |
66 |
Incorrect |
99 ms |
23120 KB |
Output isn't correct |
67 |
Correct |
86 ms |
23120 KB |
Output is correct |
68 |
Incorrect |
42 ms |
23260 KB |
Output isn't correct |
69 |
Incorrect |
42 ms |
23120 KB |
Output isn't correct |
70 |
Incorrect |
37 ms |
23112 KB |
Output isn't correct |
71 |
Incorrect |
37 ms |
23112 KB |
Output isn't correct |
72 |
Incorrect |
30 ms |
23112 KB |
Output isn't correct |
73 |
Incorrect |
31 ms |
23888 KB |
Output isn't correct |
74 |
Incorrect |
48 ms |
23900 KB |
Output isn't correct |
75 |
Incorrect |
52 ms |
23888 KB |
Output isn't correct |
76 |
Incorrect |
50 ms |
23840 KB |
Output isn't correct |
77 |
Incorrect |
53 ms |
23888 KB |
Output isn't correct |
78 |
Correct |
55 ms |
23888 KB |
Output is correct |
79 |
Incorrect |
49 ms |
23888 KB |
Output isn't correct |
80 |
Incorrect |
51 ms |
23888 KB |
Output isn't correct |
81 |
Incorrect |
54 ms |
23888 KB |
Output isn't correct |
82 |
Incorrect |
41 ms |
23888 KB |
Output isn't correct |
83 |
Incorrect |
61 ms |
23656 KB |
Output isn't correct |
84 |
Incorrect |
56 ms |
23644 KB |
Output isn't correct |
85 |
Incorrect |
54 ms |
23604 KB |
Output isn't correct |
86 |
Incorrect |
64 ms |
23624 KB |
Output isn't correct |
87 |
Incorrect |
57 ms |
23520 KB |
Output isn't correct |
88 |
Incorrect |
60 ms |
23632 KB |
Output isn't correct |
89 |
Incorrect |
61 ms |
23632 KB |
Output isn't correct |
90 |
Incorrect |
64 ms |
23624 KB |
Output isn't correct |
91 |
Incorrect |
60 ms |
23624 KB |
Output isn't correct |
92 |
Incorrect |
61 ms |
23644 KB |
Output isn't correct |