#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define in insert
#define pb push_back
#define ppb pop_back()
#define d3 ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define cans cout << ans << "\n";
#define yes cout << "Yes" << "\n";
#define no cout << "No" << "\n";
#define pll pair<ll,ll>
#define lin cout << "\n";
#define sqr 340
#define mid ((l+r)/2)
#define lc (2*x)
#define rc (2*x+1)
using namespace std;
ll n, m, d;
string s;
ll g[809][809];
bool vis[809][809];
bool vs[809][809];
ll fans[809][809];
ll t[2][2][2][2];
ll mn, ans;
ll cost;
ll timer;
void bfs(ll d1, ll d2, ll o)
{
queue<pll> q;
q.push({d1,d2});
vector<pll> v;
while(!q.empty())
{
auto it = q.front();
q.pop();
ll x = it.F, y = it.S;
if(vis[x][y]||x==0||y==0||x>n||y>m)
continue;
vis[x][y]=1;
v.pb({x,y});
if(vs[x][y])
{
cost=1e18;
break;
}
cost++;
for(int h = 0 ; 4>h ; h++)
{
ll i = x , j = y;
if(h==1)
i--;
else if(h==2)
i++;
else if(h)
j--;
else
j++;
bool l1 , l2 , l3 , l4;
l1 = l2 = l3 = l4 = 0;
l1=(i<n&&vis[i+1][j]);
l2=(i>1&&vis[i-1][j]);
l3=(j<m&&vis[i][j+1]);
l4=(j>1&&vis[i][j-1]);
if(t[l1][l2][l3][l4]>=g[i][j])
q.push({i,j});
}
}
for(auto it : v)
vis[it.F][it.S]=0;
vs[d1][d2]=1;
fans[d1][d2]=cost;
}
int main()
{
cin >> d >> n >> m;
cin >> s;
for(int i = 1 ; n>=i ; i++)
{
for(int j = 1 ; m>=j ; j++)
{
cin >> g[i][j];
if(g[i][j]==0)
g[i][j]=100001;
}
}
s+=s;
d+=d;
for(int h = 0 ; 16>h ; h++)
{
ll mx = 0;
ll c = 0;
bool l1, l2, l3, l4;
l1 = l2 = l3 = l4 = 0;
l1=((1<<0)&h);
l2=((1<<1)&h);
l3=((1<<2)&h);
l4=((1<<3)&h);
for(int i = 0 ; d>i ; i++)
{
if((s[i]=='S'&&l1)||(s[i]=='N'&&l2)||(s[i]=='E'&&l3)||(s[i]=='W'&&l4))
{
c++;
mx=max(mx,c);
}
else
c=0;
}
if(mx==d)
mx=100000;
t[l1][l2][l3][l4]=mx;
}
vector<pll> idx;
for(int i = 1 ; n>=i ; i++)
for(int j = 1 ; m>=j ; j++)
idx.pb({i,j});
random_shuffle(idx.begin(),idx.end());
mn=1e18;
timer=1;
for(int h = 0 ; idx.size()>h ; h++)
{
ll i = idx[h].F;
ll j = idx[h].S;
if(g[i][j]==100001)
continue;
cost=0;
ll o = -1;
if(vis[i][j])
o=vis[i][j];
bfs(i,j,o);
if(mn>cost)
{
ans=0;
mn=cost;
}
if(mn==cost)
ans++;
timer++;
}
cout << mn << "\n" << ans*mn;
}
Compilation message
virus.cpp: In function 'int main()':
virus.cpp:125:31: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
125 | for(int h = 0 ; idx.size()>h ; h++)
| ~~~~~~~~~~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2648 KB |
Output is correct |
2 |
Correct |
176 ms |
24708 KB |
Output is correct |
3 |
Correct |
326 ms |
26628 KB |
Output is correct |
4 |
Correct |
311 ms |
24740 KB |
Output is correct |
5 |
Correct |
200 ms |
26536 KB |
Output is correct |
6 |
Correct |
3 ms |
10584 KB |
Output is correct |
7 |
Correct |
318 ms |
23904 KB |
Output is correct |
8 |
Correct |
82 ms |
15168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
7 ms |
2968 KB |
Output is correct |
3 |
Correct |
24 ms |
2904 KB |
Output is correct |
4 |
Correct |
5 ms |
2908 KB |
Output is correct |
5 |
Correct |
22 ms |
2924 KB |
Output is correct |
6 |
Correct |
24 ms |
5112 KB |
Output is correct |
7 |
Correct |
0 ms |
2392 KB |
Output is correct |
8 |
Correct |
23 ms |
5112 KB |
Output is correct |
9 |
Correct |
2 ms |
4700 KB |
Output is correct |
10 |
Correct |
4 ms |
2908 KB |
Output is correct |
11 |
Correct |
1 ms |
4700 KB |
Output is correct |
12 |
Correct |
3 ms |
4700 KB |
Output is correct |
13 |
Correct |
22 ms |
5108 KB |
Output is correct |
14 |
Correct |
23 ms |
5112 KB |
Output is correct |
15 |
Correct |
23 ms |
5120 KB |
Output is correct |
16 |
Correct |
21 ms |
5120 KB |
Output is correct |
17 |
Correct |
13 ms |
4952 KB |
Output is correct |
18 |
Correct |
2 ms |
4952 KB |
Output is correct |
19 |
Correct |
23 ms |
5112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2648 KB |
Output is correct |
2 |
Correct |
176 ms |
24708 KB |
Output is correct |
3 |
Correct |
326 ms |
26628 KB |
Output is correct |
4 |
Correct |
311 ms |
24740 KB |
Output is correct |
5 |
Correct |
200 ms |
26536 KB |
Output is correct |
6 |
Correct |
3 ms |
10584 KB |
Output is correct |
7 |
Correct |
318 ms |
23904 KB |
Output is correct |
8 |
Correct |
82 ms |
15168 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
7 ms |
2968 KB |
Output is correct |
11 |
Correct |
24 ms |
2904 KB |
Output is correct |
12 |
Correct |
5 ms |
2908 KB |
Output is correct |
13 |
Correct |
22 ms |
2924 KB |
Output is correct |
14 |
Correct |
24 ms |
5112 KB |
Output is correct |
15 |
Correct |
0 ms |
2392 KB |
Output is correct |
16 |
Correct |
23 ms |
5112 KB |
Output is correct |
17 |
Correct |
2 ms |
4700 KB |
Output is correct |
18 |
Correct |
4 ms |
2908 KB |
Output is correct |
19 |
Correct |
1 ms |
4700 KB |
Output is correct |
20 |
Correct |
3 ms |
4700 KB |
Output is correct |
21 |
Correct |
22 ms |
5108 KB |
Output is correct |
22 |
Correct |
23 ms |
5112 KB |
Output is correct |
23 |
Correct |
23 ms |
5120 KB |
Output is correct |
24 |
Correct |
21 ms |
5120 KB |
Output is correct |
25 |
Correct |
13 ms |
4952 KB |
Output is correct |
26 |
Correct |
2 ms |
4952 KB |
Output is correct |
27 |
Correct |
23 ms |
5112 KB |
Output is correct |
28 |
Correct |
619 ms |
43600 KB |
Output is correct |
29 |
Correct |
619 ms |
44628 KB |
Output is correct |
30 |
Correct |
540 ms |
39504 KB |
Output is correct |
31 |
Correct |
468 ms |
36172 KB |
Output is correct |
32 |
Correct |
410 ms |
27556 KB |
Output is correct |
33 |
Correct |
218 ms |
24948 KB |
Output is correct |
34 |
Correct |
558 ms |
48412 KB |
Output is correct |
35 |
Correct |
423 ms |
32632 KB |
Output is correct |
36 |
Correct |
388 ms |
25256 KB |
Output is correct |
37 |
Correct |
540 ms |
31608 KB |
Output is correct |
38 |
Correct |
565 ms |
44200 KB |
Output is correct |
39 |
Correct |
215 ms |
25180 KB |
Output is correct |
40 |
Correct |
261 ms |
25700 KB |
Output is correct |
41 |
Correct |
184 ms |
24508 KB |
Output is correct |
42 |
Correct |
477 ms |
36300 KB |
Output is correct |
43 |
Correct |
567 ms |
35920 KB |
Output is correct |
44 |
Correct |
90 ms |
15204 KB |
Output is correct |