제출 #742280

#제출 시각아이디문제언어결과실행 시간메모리
742280irmuunTracks in the Snow (BOI13_tracks)C++17
82.50 / 100
2096 ms153392 KiB
#include<bits/stdc++.h>
 
using namespace std;
 
#define pb push_back
#define ll long long
#define ff first
#define ss second
#define all(s) s.begin(),s.end()

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int h,w;
    cin>>h>>w;
    string s[h+5];
    int used[h+5][w+5];
    memset(used,0,sizeof(used));
    int cnt=0;
    for(int i=0;i<h;i++){
        cin>>s[i];
    }
    set<pair<int,pair<int,int>>>st;
    st.insert({1,{0,0}});
    used[0][0]=1;
    int ans=0;
    pair<int,pair<int,int>>p;
    while(!st.empty()){
        p=*st.begin();
        int num=p.ff,x=p.ss.ff,y=p.ss.ss;
        ans=max(ans,num);
        st.erase(p);
        if(x>0&&used[x-1][y]==0){
            used[x-1][y]=1;
            if(s[x-1][y]==s[x][y]){
                st.insert({num,{x-1,y}});
            }
            else if(s[x-1][y]!='.'){
                st.insert({num+1,{x-1,y}});
            }
        }
        if(x<h-1&&used[x+1][y]==0){
            used[x+1][y]=1;
            if(s[x+1][y]==s[x][y]){
                st.insert({num,{x+1,y}});
            }
            else if(s[x+1][y]!='.'){
                st.insert({num+1,{x+1,y}});
            }
        }
        if(y>0&&used[x][y-1]==0){
            used[x][y-1]=1;
            if(s[x][y-1]==s[x][y]){
                st.insert({num,{x,y-1}});
            }
            else if(s[x][y-1]!='.'){
                st.insert({num+1,{x,y-1}});
            }
        }
        if(y<w-1&&used[x][y+1]==0){
            used[x][y+1]=1;
            if(s[x][y+1]==s[x][y]){
                st.insert({num,{x,y+1}});
            }
            else if(s[x][y+1]!='.'){
                st.insert({num+1,{x,y+1}});
            }
        }
    }
    cout<<ans;
}

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

tracks.cpp: In function 'int main()':
tracks.cpp:18:9: warning: unused variable 'cnt' [-Wunused-variable]
   18 |     int cnt=0;
      |         ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...