This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimization O2
#pragma GCC optimization "unroll-loop"
#pragma target ("avx2")
#include <bits/stdc++.h>
#define ll int
#define ld long double
#define fs first
#define sc second
using namespace std;
typedef pair<ll,ll> LL;
const ll N = 4e3 + 9;
const ll Log2 = 20;
const ll inf = 1e9 + 7;
char c;
ll n,m,a[N][N],cnt,ans,was[N][N];
ll dx[4] = {0,0,1,-1};
ll dy[4] = {1,-1,0,0};
bool chk(ll x,ll y){
return x <= n&&y <= m&&x > 0&&y > 0;
}
queue<LL> q,differ;
int main(){
ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
#define task "test"
if (fopen(task".INP","r")){
freopen(task".INP","r",stdin);
//freopen(task".OUT","w",stdout);
}
cin>>n>>m;
for (ll i = 1;i <= n;i++)
for (ll j = 1;j <= m;j++){
cin>>c; cnt += (c != '.');
if (c == '.') a[i][j] = 2;
if (c == 'F') a[i][j] = 1;
}
ll now = a[1][1],cur = 0; was[1][1] = 1; q.push({1,1});
while(cur < cnt){
ans++;
while(!q.empty()){
LL t = q.front(); q.pop(); cur++;
for (ll i = 0;i < 4;i++){
ll x = t.fs + dx[i],y = t.sc + dy[i];
if (!chk(x,y) || was[x][y]) continue;
was[x][y] = 1;
if (a[x][y] == now) q.push({x,y});
else if (a[x][y] == 1 - now) differ.push({x,y});
}
}
//cout<<cur; return 0;
now ^= 1;
while(!differ.empty()) q.push(differ.front()),differ.pop();
}
cout<<ans;
}
Compilation message (stderr)
tracks.cpp:1: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
1 | #pragma GCC optimization O2
|
tracks.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
2 | #pragma GCC optimization "unroll-loop"
|
tracks.cpp:3: warning: ignoring '#pragma target ' [-Wunknown-pragmas]
3 | #pragma target ("avx2")
|
tracks.cpp: In function 'int main()':
tracks.cpp:31:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
31 | freopen(task".INP","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |