Submission #749166

#TimeUsernameProblemLanguageResultExecution timeMemory
749166nononoTracks in the Snow (BOI13_tracks)C++14
2.19 / 100
569 ms34660 KiB
#include "bits/stdc++.h"
using namespace std;

const int mxN = 4e3 + 10;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};

int n, m;
char a[mxN][mxN];
bool mark[mxN][mxN];

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

signed main(){

    #define name "test"
    if(fopen(name".inp", "r")){
        freopen(name".inp", "r", stdin);
        freopen(name".out", "w", stdout);
    }

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    cin >> n >> m;
    
    for(int i = 1; i <= n; i ++){
        for(int j = 1; j <= m; j ++){
            cin >> a[i][j];
        }
    }
    
    if(a[1][1] == '.'){
        cout << 0 << "\n";
        return 0;
    }
    
    memset(mark, false, sizeof(mark));
    
    int res = 1;
    queue<pair<int, int>> qu;
    qu.push({1, 1});
    mark[1][1] = true;
    
    while(!qu.empty()){
        pair<int, int> c = qu.front();
        qu.pop();
        
        for(int i = 0; i < 4; i ++){
            int x = c.first + dx[i];
            int y = c.second + dy[i];
            
            if(inside(x, y) && a[x][y] == a[c.first][c.second] && !mark[x][y]){
                qu.push({x, y});
                mark[x][y] = true;
            }
        }
    }
    
    bool check = true, Check = true;
    
    for(int i = 1; i <= n; i ++){
        for(int j = 1; j <= m; j ++){
            if(mark[i][j]) continue ;
            
            if(a[i][j] == 'F'){
                res += check;
                check = false;
            }
            
            if(a[i][j] == 'R'){
                res += Check;
                Check = false;
            }
        }
    }
    
    cout << res << "\n";
    return 0;
}

Compilation message (stderr)

tracks.cpp: In function 'int main()':
tracks.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         freopen(name".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
tracks.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(name".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...