제출 #892441

#제출 시각아이디문제언어결과실행 시간메모리
892441tnknguyen_Tracks in the Snow (BOI13_tracks)C++14
19.79 / 100
962 ms265892 KiB
#include <bits/stdc++.h>
using namespace std;
#define endl '\n' 
/**
* IDEA:
*/

const int sz = 4e3 + 5;
int m, n;
int a[sz][sz], vi[sz][sz], d[sz][sz];
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

bool valid(int x, int y){
    return (x >= 1 && x <= m && y >= 1 && y <= n);
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    // freopen("main.inp","r",stdin);
    // freopen("main.out","w",stdout);

    cin>>m>>n;

    for(int i=1;i<=m;++i){
        for(int j=1;j<=n;++j){
            char c;
            cin>>c;
            if(c == '.'){
                a[i][j] == -1;
            }
            if(c == 'F'){
                a[i][j] = 1;
            }
            else{
                a[i][j] = 2;
            }
        }
    }

    deque<pair<int,int>> q;
    q.push_front({1, 1});
    vi[1][1] = 1;
    d[1][1] = 1;

    int ans = 0;
    while(q.size()){
        int x = q.front().first;
        int y = q.front().second;
        q.pop_front();

        ans = max(ans, d[x][y]);

        for(int i=0;i<4;++i){
            int u = x + dx[i];
            int v = y + dy[i];
            int c = (a[x][y] != a[u][v]);
            if(valid(u, v) && !vi[u][v] && a[u][v] != -1){
                d[u][v] = d[x][y] + c;
                vi[u][v] = 1;
                if(!c){
                    q.push_front({u, v});
                }
                else{
                    q.push_back({u, v});
                }
            }
        }
    }

    cout<<ans;

    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

tracks.cpp: In function 'int main()':
tracks.cpp:33:25: warning: statement has no effect [-Wunused-value]
   33 |                 a[i][j] == -1;
      |                 ~~~~~~~~^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...