답안 #753754

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
753754 2023-06-05T22:21:37 Z tiwerlol Tracks in the Snow (BOI13_tracks) C++14
100 / 100
510 ms 160704 KB
#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();
}

Compilation message

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++)
      |                        ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 6356 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 724 KB Output is correct
4 Correct 7 ms 5844 KB Output is correct
5 Correct 3 ms 3284 KB Output is correct
6 Correct 1 ms 456 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 1 ms 852 KB Output is correct
9 Correct 1 ms 1108 KB Output is correct
10 Correct 3 ms 2900 KB Output is correct
11 Correct 3 ms 2260 KB Output is correct
12 Correct 5 ms 3412 KB Output is correct
13 Correct 3 ms 3408 KB Output is correct
14 Correct 3 ms 3284 KB Output is correct
15 Correct 11 ms 6476 KB Output is correct
16 Correct 12 ms 6468 KB Output is correct
17 Correct 9 ms 6228 KB Output is correct
18 Correct 6 ms 5844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 31444 KB Output is correct
2 Correct 44 ms 23372 KB Output is correct
3 Correct 198 ms 126024 KB Output is correct
4 Correct 71 ms 45556 KB Output is correct
5 Correct 165 ms 95056 KB Output is correct
6 Correct 510 ms 139440 KB Output is correct
7 Correct 15 ms 32852 KB Output is correct
8 Correct 14 ms 31444 KB Output is correct
9 Correct 2 ms 848 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 16 ms 32312 KB Output is correct
12 Correct 2 ms 1620 KB Output is correct
13 Correct 42 ms 23104 KB Output is correct
14 Correct 25 ms 15060 KB Output is correct
15 Correct 25 ms 16580 KB Output is correct
16 Correct 19 ms 8868 KB Output is correct
17 Correct 106 ms 49028 KB Output is correct
18 Correct 87 ms 48472 KB Output is correct
19 Correct 73 ms 45544 KB Output is correct
20 Correct 54 ms 42128 KB Output is correct
21 Correct 129 ms 98260 KB Output is correct
22 Correct 147 ms 95052 KB Output is correct
23 Correct 192 ms 79440 KB Output is correct
24 Correct 134 ms 97132 KB Output is correct
25 Correct 388 ms 126268 KB Output is correct
26 Correct 310 ms 160704 KB Output is correct
27 Correct 362 ms 143992 KB Output is correct
28 Correct 501 ms 139592 KB Output is correct
29 Correct 496 ms 139916 KB Output is correct
30 Correct 443 ms 138508 KB Output is correct
31 Correct 463 ms 101768 KB Output is correct
32 Correct 321 ms 141788 KB Output is correct