답안 #813453

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
813453 2023-08-07T18:08:56 Z birthdaycake Tracks in the Snow (BOI13_tracks) C++17
100 / 100
1096 ms 223952 KB
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
 
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
 
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
 
 
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <fstream>
#define endl '\n'
#define int long long
#define mod 1000000007
using namespace std;

char m[4001][4001];
int dx[] = {0,0,1,-1};
int dy[] = {1,-1,0,0};
int dist[4001][4001];
signed main(){
    
    
    int h,w, ans = 0; cin >> h >> w;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> m[i][j];
        }
    }
    dist[0][0] = 1;
    deque<pair<int,int>>d;
    d.push_front({0,0});
    while(d.size()){
        auto x = d.front();
        ans = max(ans, dist[x.first][x.second]);
        d.pop_front();
        for(int i = 0; i < 4; i++){
            int aa = x.first + dx[i], bb = x.second + dy[i];
            int val = dist[x.first][x.second]; 
            if(aa < 0 or bb < 0 or aa >= h or bb >= w) continue;
            if(m[aa][bb] == '.' or dist[aa][bb] != 0) continue;
            if(m[aa][bb] != m[x.first][x.second]){
                dist[aa][bb] = val + 1;
                d.push_back({aa,bb});
            }else{
                dist[aa][bb] = val;
                d.push_front({aa,bb});
            }
            
        }
    }
    
    cout << ans;
    
    
    
}
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 6100 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 11 ms 5844 KB Output is correct
5 Correct 5 ms 3156 KB Output is correct
6 Correct 0 ms 468 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
9 Correct 1 ms 1108 KB Output is correct
10 Correct 4 ms 2516 KB Output is correct
11 Correct 3 ms 2336 KB Output is correct
12 Correct 7 ms 3284 KB Output is correct
13 Correct 5 ms 3156 KB Output is correct
14 Correct 5 ms 3156 KB Output is correct
15 Correct 16 ms 5716 KB Output is correct
16 Correct 17 ms 6200 KB Output is correct
17 Correct 14 ms 5844 KB Output is correct
18 Correct 11 ms 5764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 30976 KB Output is correct
2 Correct 84 ms 16716 KB Output is correct
3 Correct 665 ms 75340 KB Output is correct
4 Correct 186 ms 42708 KB Output is correct
5 Correct 361 ms 62340 KB Output is correct
6 Correct 1095 ms 167632 KB Output is correct
7 Correct 16 ms 32340 KB Output is correct
8 Correct 17 ms 30948 KB Output is correct
9 Correct 3 ms 724 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 17 ms 31700 KB Output is correct
12 Correct 2 ms 1620 KB Output is correct
13 Correct 79 ms 16676 KB Output is correct
14 Correct 46 ms 11444 KB Output is correct
15 Correct 48 ms 16008 KB Output is correct
16 Correct 38 ms 6512 KB Output is correct
17 Correct 197 ms 32272 KB Output is correct
18 Correct 188 ms 47288 KB Output is correct
19 Correct 169 ms 42748 KB Output is correct
20 Correct 141 ms 26952 KB Output is correct
21 Correct 382 ms 53984 KB Output is correct
22 Correct 353 ms 62320 KB Output is correct
23 Correct 423 ms 49724 KB Output is correct
24 Correct 373 ms 52596 KB Output is correct
25 Correct 872 ms 141188 KB Output is correct
26 Correct 1035 ms 223952 KB Output is correct
27 Correct 1042 ms 177692 KB Output is correct
28 Correct 1077 ms 167724 KB Output is correct
29 Correct 1044 ms 163160 KB Output is correct
30 Correct 1055 ms 172952 KB Output is correct
31 Correct 686 ms 106596 KB Output is correct
32 Correct 1096 ms 167924 KB Output is correct