Please sign in first.
Submission #18351753
Source Code Expand
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define F first
#define S second
using namespace std;
int main()
{
ll n,m;
cin>>n>>m;
char a[n+1][m+1];
ll sx,sy,ex,ey;
vector<pair<ll,ll>>tele[3000];
for(ll i=0;i<n;i++)
{
for(ll j=0;j<m;j++)
{
cin>>a[i][j];
if(a[i][j]=='S')
{
sx=i;
sy=j;
}
if(a[i][j]=='G')
{
ex=i;
ey=j;
}
if(islower(a[i][j]))
{
tele[a[i][j]-'a'].pb(mp(i,j));
}
}
}
queue<pair<ll,ll>>q;
q.push(mp(sx,sy));
ll vis[3000][3000];
ll dp[3000][3000];
memset(vis,0,sizeof(vis));
memset(dp,-1,sizeof(dp));
vis[sx][sy]=1;
dp[sx][sy]=0;
while(!q.empty())
{
ll x=q.front().F;
ll y=q.front().S;
q.pop();
ll dx[4]={0,0,1,-1};
ll dy[4]={1,-1,0,0};
for(ll i=0;i<4;i++)
{
ll x1=x+dx[i];
ll y1=y+dy[i];
if(x1>=0&&x1<n&&y1>=0&&y1<m&&vis[x1][y1]==0&&a[x1][y1]!='#')
{
vis[x1][y1]=1;
q.push(mp(x1,y1));
dp[x1][y1]=dp[x][y]+1;
}
}
if(islower(a[x][y]))
{
ll c=a[x][y]-'a';
for(ll i=0;i<tele[c].size();i++)
{
ll x1=tele[c][i].F;
ll y1=tele[c][i].S;
if(x1==x&&y1==y)
continue;
if(vis[x1][y1]==0)
{
vis[x1][y1]=1;
dp[x1][y1]=dp[x][y]+1;
q.push(mp(x1,y1));
// tele[c].clear();
}
}
}
}
cout<<dp[ex][ey];
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | E - Third Avenue |
| User | dazzle |
| Language | C++ (GCC 9.2.1) |
| Score | 0 |
| Code Size | 1984 Byte |
| Status | TLE |
| Exec Time | 3312 ms |
| Memory | 155524 KiB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:66:25: warning: comparison of integer expressions of different signedness: ‘long long int’ and ‘std::vector<std::pair<long long int, long long int> >::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
66 | for(ll i=0;i<tele[c].size();i++)
| ~^~~~~~~~~~~~~~~
./Main.cpp:44:15: warning: ‘sy’ may be used uninitialized in this function [-Wmaybe-uninitialized]
44 | dp[sx][sy]=0;
| ~~~~~~~~~~^~
./Main.cpp:44:15: warning: ‘sx’ may be used uninitialized in this function [-Wmaybe-uninitialized]
./Main.cpp:82:20: warning: ‘ex’ may be used uninitialized in this function [-Wmaybe-uninitialized]
82 | cout<<dp[ex][ey];
| ^
./Main.cpp:82:20: warning: ‘ey’ may be used uninitialized in this function [-Wmaybe-uninitialized]
Judge Result
| Set Name | Sample | All | ||||||
|---|---|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 0 / 500 | ||||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | sample_01.txt, sample_02.txt, sample_03.txt |
| All | hand_01.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, sample_01.txt, sample_02.txt, sample_03.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| hand_01.txt | AC | 95 ms | 144300 KiB |
| random_01.txt | AC | 90 ms | 144204 KiB |
| random_02.txt | AC | 94 ms | 144336 KiB |
| random_03.txt | AC | 89 ms | 144200 KiB |
| random_04.txt | AC | 90 ms | 144144 KiB |
| random_05.txt | AC | 92 ms | 144300 KiB |
| random_06.txt | AC | 90 ms | 144132 KiB |
| random_07.txt | AC | 92 ms | 144340 KiB |
| random_08.txt | AC | 91 ms | 144256 KiB |
| random_09.txt | AC | 89 ms | 144232 KiB |
| random_10.txt | AC | 92 ms | 144256 KiB |
| random_11.txt | AC | 94 ms | 144124 KiB |
| random_12.txt | AC | 88 ms | 144340 KiB |
| random_13.txt | AC | 93 ms | 144336 KiB |
| random_14.txt | AC | 91 ms | 144200 KiB |
| random_15.txt | AC | 88 ms | 144204 KiB |
| random_16.txt | AC | 112 ms | 144652 KiB |
| random_17.txt | AC | 342 ms | 147816 KiB |
| random_18.txt | AC | 255 ms | 147168 KiB |
| random_19.txt | AC | 108 ms | 144604 KiB |
| random_20.txt | AC | 303 ms | 147172 KiB |
| random_21.txt | AC | 92 ms | 144220 KiB |
| random_22.txt | AC | 97 ms | 144404 KiB |
| random_23.txt | TLE | 3312 ms | 151580 KiB |
| random_24.txt | TLE | 3312 ms | 151824 KiB |
| random_25.txt | AC | 113 ms | 144552 KiB |
| random_26.txt | AC | 89 ms | 144276 KiB |
| random_27.txt | AC | 202 ms | 145744 KiB |
| random_28.txt | AC | 98 ms | 144336 KiB |
| random_29.txt | AC | 91 ms | 144224 KiB |
| random_30.txt | TLE | 3312 ms | 152600 KiB |
| random_31.txt | AC | 977 ms | 152460 KiB |
| random_32.txt | TLE | 3034 ms | 155524 KiB |
| random_33.txt | AC | 357 ms | 148080 KiB |
| random_34.txt | AC | 261 ms | 148056 KiB |
| sample_01.txt | AC | 92 ms | 144180 KiB |
| sample_02.txt | AC | 89 ms | 144300 KiB |
| sample_03.txt | AC | 90 ms | 144200 KiB |