#include <bits/stdc++.h>
#define ve vector
#define vi vector<int>
#define vii vector<ii>
#define ii pair<int,int>
#define fi first
#define se second
#define ll long long
#define INF 1e9+7
#define pb push_back
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using Tree = tree<T, null_type, less<T>, rb_tree_tag,
tree_order_statistics_node_update>;
const int MOD = 1e9+7;
const int nax = 800+5;
void readio(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int grid[nax][nax], vis[nax][nax];
int mx[16];
int ad[4][2] = {{1,0}, {-1,0}, {0,-1}, {0,1}};
map<char,int> mp;
int m,r,c;
int dfs(int x, int y){
vis[x][y] = 1;
int res = 1;
for(int k = 0; k < 4; k++){
int nx = x + ad[k][0], ny = y + ad[k][1];
if(nx < 0 || ny < 0 || nx >= r || ny >= c || vis[nx][ny] || !grid[nx][ny]) continue;
int cur = 0;
for(int i = 0; i < 4; i++){
int vx = nx + ad[i][0], vy = ny + ad[i][1];
if(vx < 0 || vy < 0 || vx >= r || vy >= c || grid[vx][vy] == 0) continue;
if(vis[vx][vy]) cur += (1 << i);
}
//cout << nx << " " << ny<< " " << cur << " " << mx[cur] << endl;
if(grid[nx][ny] > mx[cur]) continue;
res += dfs(nx, ny);
}
return res;
}
int main()
{
optimise;
cin >> m >> r >> c;
string wind;
cin >> wind;
wind = wind + wind;
mp['S'] = 0, mp['N'] = 1, mp['W'] = 2, mp['E'] = 3;
for (int i = 0; i < 16; ++i)
{
int cur = 0;
for (int k = 0; k < wind.size(); ++k)
{
bool test = false;
for (int j = 0; j < 4; ++j)
{
if(i & (1 << j)){
if(mp[wind[k]] == j) test = true;
}
}
if(test) cur++;
else cur = 0;
mx[i] = max(mx[i], cur);
}
if(mx[i] == wind.size()) mx[i] = INF;
}
if(mx[1] == wind.size()) mx[1] = INF;
if(mx[2] == wind.size()) mx[2] = INF;
if(mx[4] == wind.size()) mx[4] = INF;
if(mx[8] == wind.size()) mx[8] = INF;
for (int i = 0; i < r; ++i)
{
for (int j = 0; j < c; ++j)
{
cin >> grid[i][j];
}
}
int mn = INF, aff = 0;
if(r <= 50 && c <= 50){
for(int i = 0; i < r; i++){
for(int j = 0; j < c; j++){
if(!grid[i][j]) continue;
memset(vis, 0, sizeof vis);
int cur = dfs(i, j);
//cout << i << " " << j << " " << cur << endl;
if(mn > cur) mn = cur, aff = 1;
else if(mn == cur) aff++;
}
}
} else {
for (int i = 0; i < r; ++i)
{
int low = 0, high = 1;
for (int j = 0; j < c; ++j)
{
low = min(low, j);
high = max(high, j+1);
if(!grid[i][j]) {
low = j+1;
continue;
}
if(grid[i][j-1] > mx[8]) low = j;
while(high < c && grid[i][high] <= mx[4] && grid[i][high] != 0) high++;
int cur = high - low;
//cout << j << " " << low << " " << high << endl;
if(mn > cur) mn = cur, aff = 1;
else if(mn == cur) aff++;
}
}
}
cout << mn << " " << aff << endl;
}
Compilation message
virus.cpp: In function 'int main()':
virus.cpp:60:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | for (int k = 0; k < wind.size(); ++k)
| ~~^~~~~~~~~~~~~
virus.cpp:73:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
73 | if(mx[i] == wind.size()) mx[i] = INF;
| ~~~~~~^~~~~~~~~~~~~~
virus.cpp:76:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
76 | if(mx[1] == wind.size()) mx[1] = INF;
| ~~~~~~^~~~~~~~~~~~~~
virus.cpp:77:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
77 | if(mx[2] == wind.size()) mx[2] = INF;
| ~~~~~~^~~~~~~~~~~~~~
virus.cpp:78:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
78 | if(mx[4] == wind.size()) mx[4] = INF;
| ~~~~~~^~~~~~~~~~~~~~
virus.cpp:79:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
79 | if(mx[8] == wind.size()) mx[8] = INF;
| ~~~~~~^~~~~~~~~~~~~~
virus.cpp: In function 'void readio()':
virus.cpp:22:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
22 | freopen("input.txt", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
virus.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
23 | freopen("output.txt", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
3028 KB |
Output is correct |
2 |
Correct |
30 ms |
2812 KB |
Output is correct |
3 |
Correct |
38 ms |
2784 KB |
Output is correct |
4 |
Correct |
25 ms |
2728 KB |
Output is correct |
5 |
Correct |
41 ms |
2896 KB |
Output is correct |
6 |
Correct |
1 ms |
2772 KB |
Output is correct |
7 |
Correct |
67 ms |
3084 KB |
Output is correct |
8 |
Correct |
56 ms |
2176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2772 KB |
Output is correct |
2 |
Correct |
35 ms |
3084 KB |
Output is correct |
3 |
Correct |
60 ms |
3212 KB |
Output is correct |
4 |
Correct |
30 ms |
3216 KB |
Output is correct |
5 |
Correct |
54 ms |
3084 KB |
Output is correct |
6 |
Correct |
278 ms |
3440 KB |
Output is correct |
7 |
Correct |
6 ms |
2772 KB |
Output is correct |
8 |
Correct |
57 ms |
3328 KB |
Output is correct |
9 |
Correct |
156 ms |
3028 KB |
Output is correct |
10 |
Correct |
31 ms |
3192 KB |
Output is correct |
11 |
Correct |
103 ms |
3000 KB |
Output is correct |
12 |
Correct |
317 ms |
3080 KB |
Output is correct |
13 |
Correct |
223 ms |
3616 KB |
Output is correct |
14 |
Correct |
213 ms |
3440 KB |
Output is correct |
15 |
Correct |
214 ms |
3628 KB |
Output is correct |
16 |
Correct |
236 ms |
3560 KB |
Output is correct |
17 |
Correct |
121 ms |
3132 KB |
Output is correct |
18 |
Correct |
108 ms |
3028 KB |
Output is correct |
19 |
Correct |
142 ms |
3440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
3028 KB |
Output is correct |
2 |
Correct |
30 ms |
2812 KB |
Output is correct |
3 |
Correct |
38 ms |
2784 KB |
Output is correct |
4 |
Correct |
25 ms |
2728 KB |
Output is correct |
5 |
Correct |
41 ms |
2896 KB |
Output is correct |
6 |
Correct |
1 ms |
2772 KB |
Output is correct |
7 |
Correct |
67 ms |
3084 KB |
Output is correct |
8 |
Correct |
56 ms |
2176 KB |
Output is correct |
9 |
Correct |
4 ms |
2772 KB |
Output is correct |
10 |
Correct |
35 ms |
3084 KB |
Output is correct |
11 |
Correct |
60 ms |
3212 KB |
Output is correct |
12 |
Correct |
30 ms |
3216 KB |
Output is correct |
13 |
Correct |
54 ms |
3084 KB |
Output is correct |
14 |
Correct |
278 ms |
3440 KB |
Output is correct |
15 |
Correct |
6 ms |
2772 KB |
Output is correct |
16 |
Correct |
57 ms |
3328 KB |
Output is correct |
17 |
Correct |
156 ms |
3028 KB |
Output is correct |
18 |
Correct |
31 ms |
3192 KB |
Output is correct |
19 |
Correct |
103 ms |
3000 KB |
Output is correct |
20 |
Correct |
317 ms |
3080 KB |
Output is correct |
21 |
Correct |
223 ms |
3616 KB |
Output is correct |
22 |
Correct |
213 ms |
3440 KB |
Output is correct |
23 |
Correct |
214 ms |
3628 KB |
Output is correct |
24 |
Correct |
236 ms |
3560 KB |
Output is correct |
25 |
Correct |
121 ms |
3132 KB |
Output is correct |
26 |
Correct |
108 ms |
3028 KB |
Output is correct |
27 |
Correct |
142 ms |
3440 KB |
Output is correct |
28 |
Incorrect |
77 ms |
4480 KB |
Output isn't correct |
29 |
Halted |
0 ms |
0 KB |
- |