Submission #1120272

#TimeUsernameProblemLanguageResultExecution timeMemory
1120272vjudge1Tracks in the Snow (BOI13_tracks)C++17
100 / 100
1459 ms381416 KiB
/**
██╗░░██╗████████╗██╗░░░░░███╗░░░███╗
██║░░██║╚══██╔══╝██║░░░░░████╗░████║
███████║░░░██║░░░██║░░░░░██╔████╔██║
██╔══██║░░░██║░░░██║░░░░░██║╚██╔╝██║
██║░░██║░░░██║░░░███████╗██║░╚═╝░██║
╚═╝░░╚═╝░░░╚═╝░░░╚══════╝╚═╝░░░░░╚═╝
**/

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

#define int l
#define f first
#define ara <<" "<<
#define s second
#define endl '\n'
#define l long long
#define pb push_back
#define pairs pair<l,l>
#define all(v) v.begin(),v.end()
#define yesno(v) ((v) ? "YES" : "NO")
#define dbg(x) cout<<#x<<" = "<<x<<endl;
#define filereader() ifstream cin(input);
#define fileprinter() ofstream cout(output);
#define fast ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL);


using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less_equal<int> , rb_tree_tag, tree_order_statistics_node_update> indexed_set;

ifstream in;
ofstream out;

l gcd(l a, l b){
    return (b == 0) ? a : gcd(b, a%b);
}

const l N = 4000 + 5;
const l INF = 1e18;
const l mod = 1e9 + 7;

const string  input =  "input.txt";
const string output = "output.txt";


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

char chr;

queue<pairs>q;

vector<vector<char>>a(N,vector<char>(N,'.'));
vector<vector<bool>>ch(N,vector<bool>(N,0));



void dfs(l x,l y){

    ch[x][y] = 1;


    for(int i = 0 ; i < 4;i++){
        l tx = dx[i] + x;
        l ty = dy[i] + y;

        if(a[tx][ty] == '.'){
            continue;
        }
        if(a[tx][ty] == chr){
            if(ch[tx][ty] == 0)
                dfs(tx,ty);
            continue;
        }
        else{
            q.push({tx,ty});
        }
    }

}



signed main(){
    //fast;
    system("color a");


    l n,m;
    cin>>n>>m;
    l temp1 = 0, temp2 = 0;

    for(int i = 1 ; i <= n ; i++){
        for(int j = 1; j <= m ;j++){
            cin>>a[i][j];
            if(a[i][j] == 'R'){
                temp1 ++;
            }
            if(a[i][j] == 'F'){
                temp2 ++;
            }
        }
    }

    if(temp1 == 0 and temp2 == 0){
        cout<<0;return 0;
    }
    if(temp1 != 0 and temp2 == 0){
        cout<<1;return 0;
    }
    if(temp1 == 0 and temp2 != 0){
        cout<<1;return 0;
    }



    q.push({1,1});

    l ans = 0;
    chr = '.';

    while(q.size()){
        pairs p = q.front();q.pop();
        //system("pause");

        if(ch[p.f][p.s]){
            continue;
        }

        //cout<<p.f<<" "<<p.s<<endl;
        if(chr != a[p.f][p.s])
            ans ++;

        chr =  a[p.f][p.s];
        dfs(p.f,p.s);

    }
    cout<<ans<<endl;



}

Compilation message (stderr)

tracks.cpp: In function 'int main()':
tracks.cpp:90:11: warning: ignoring return value of 'int system(const char*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   90 |     system("color a");
      |     ~~~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...