This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 = 70+5;
void readio(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int grid[nax][nax];
int mx[4];
int ad[4][2] = {{-1,0}, {1,0}, {0,1}, {0,-1}};
map<char,int> mp;
int m,r,c;
bool vis[nax][nax];
int dfs(int x, int y){
vis[x][y] = 1;
int cur = 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] > mx[k] || !grid[nx][ny]) continue;
cur += dfs(nx, ny);
}
return cur;
}
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;
int cur = 0;
for (int i = 0; i < wind.size(); ++i)
{
if(i && wind[i] != wind[i-1]) cur = 0;
cur++;
mx[mp[wind[i]]] = max(cur, mx[mp[wind[i]]]);
}
if(mx[2] == wind.size()) mx[2] = INF;
if(mx[3] == wind.size()) mx[3] = INF;
for (int i = 0; i < r; ++i)
{
for (int j = 0; j < c; ++j)
{
cin >> grid[i][j];
}
}
int mn = INF, aff = 0;
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);
if(mn > cur) mn = cur, aff = 1;
else if(mn == cur) aff++;
}
}
cout << mn << " " << aff << endl;
}
Compilation message (stderr)
virus.cpp: In function 'int main()':
virus.cpp:51:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | for (int i = 0; i < wind.size(); ++i)
| ~~^~~~~~~~~~~~~
virus.cpp:57:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | if(mx[2] == wind.size()) mx[2] = INF;
| ~~~~~~^~~~~~~~~~~~~~
virus.cpp:58:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | if(mx[3] == wind.size()) mx[3] = 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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |