이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <map>
#include <climits>
#include <fstream>
#include <vector>
#include <stack>
#include <cmath>
#include <bitset>
#include <chrono>
#include <random>
#include <algorithm>
#include <set>
#include <queue>
using namespace std;
///ofstream cout("apm.out");
///ifstream cin("apm.in");
const int MOD = 1e9+7;
int di[4] = {-1, 1, 0, 0};
int dj[4] = {0, 0, -1, 1};
int mat[4001][4001];
int D[4001][4001];
void solve()
{
int n, m; cin >> n >> m;
for(int z = 0; z < n; z++)
{
string s; cin >> s;
for(int x = 0; x < s.size(); x++)
{
if(s[x]=='.') mat[z+1][x+1] = 1;
else if(s[x]=='R') mat[z+1][x+1] = 2;
else mat[z+1][x+1] = 3;
D[z+1][x+1] = 0;
}
}
deque<pair<int, int>> pQ;
pQ.push_back(make_pair(1, 1));
D[1][1] = 1;
int ans = 1;
while(!pQ.empty())
{
int i = pQ.front().first, j = pQ.front().second;
ans = max(ans, D[i][j]);
pQ.pop_front();
for(int k = 0; k < 4; k++)
{
int ki = di[k] + i, kj = dj[k] + j;
if((ki>=1&&ki<=n&&kj>=1&&kj<=m) && D[ki][kj]==0 && mat[ki][kj]!=1)
{
D[ki][kj] = D[i][j] + (mat[i][j]!=mat[ki][kj]);
if(mat[i][j]!=mat[ki][kj]) pQ.push_back(make_pair(ki, kj));
else pQ.push_front(make_pair(ki, kj));
}
}
}
cout << ans;
}
int main()
{
cout.tie(NULL);
cin.tie(NULL);
ios_base::sync_with_stdio(false);
int tt = 1; //cin >> tt;
while(tt--)
solve();
}
컴파일 시 표준 에러 (stderr) 메시지
tracks.cpp: In function 'void solve()':
tracks.cpp:36:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | for(int x = 0; x < s.size(); x++)
| ~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |