# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
598330 | Hanksburger | Mecho (IOI09_mecho) | C++17 | 384 ms | 39132 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
vector<int> adj[640005], bee;
queue<pair<int, int> > qq;
char a[640005];
bool b[640005];
int d[640005];
queue<int> q;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, p, s, e, l, r;
cin >> n >> p;
for (int i=0; i<n*n; i++)
{
cin >> a[i];
if (a[i]=='M')
s=i;
else if (a[i]=='D')
e=i;
else if (a[i]=='H')
bee.push_back(i);
if (a[i]!='T')
{
a[i]='G';
if (i>=n && a[i-n]=='G')
{
adj[i].push_back(i-n);
adj[i-n].push_back(i);
}
if (i%n && a[i-1]=='G')
{
adj[i].push_back(i-1);
adj[i-1].push_back(i);
}
}
}
for (int u:bee)
{
b[u]=1;
q.push(u);
}
while (!q.empty())
{
int u=q.front();
q.pop();
for (int v:adj[u])
{
if (!b[v] && v!=e)
{
d[v]=d[u]+1;
b[v]=1;
q.push(v);
}
}
}
l=-1;
r=d[s]-1;
while (l<r)
{
int m=(l+r+1)/2;
for (int i=0; i<n*n; i++)
b[i]=0;
qq.push({s, 0});
b[s]=1;
bool ok=0;
while (!qq.empty())
{
int u=qq.front().first, w=qq.front().second;
qq.pop();
for (int v:adj[u])
{
if (v==e)
{
ok=1;
break;
}
if (!b[v] && w+1<(d[v]-m)*p)
{
b[v]=1;
qq.push({v, w+1});
}
}
if (ok)
while (!qq.empty())
qq.pop();
}
if (ok)
l=m;
else
r=m-1;
}
cout << l;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |