답안 #948819

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
948819 2024-03-18T14:51:40 Z steveonalex Tracks in the Snow (BOI13_tracks) C++14
100 / 100
573 ms 195152 KB
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define MASK(i) (1ULL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()
 
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
 
ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ll mask){return __builtin_popcountll(mask);}
int ctz(ull mask){return __builtin_ctzll(mask);}
int logOf(ull mask){return 63 - __builtin_clzll(mask);}
 
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}
 
template <class T1, class T2>
    bool maximize(T1 &a, T2 b){
        if (a < b) {a = b; return true;}
        return false;
    }
 
template <class T1, class T2>
    bool minimize(T1 &a, T2 b){
        if (a > b) {a = b; return true;}
        return false;
    }
 
template <class T>
    void printArr(T& container, string separator = " ", string finish = "\n", ostream &out = cout){
        for(auto item: container) out << item << separator;
        out << finish;
    }
 
template <class T>
    void remove_dup(vector<T> &a){
        sort(ALL(a));
        a.resize(unique(ALL(a)) - a.begin());
    }

const int N = 4009;

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

int n, m;
int grid[N][N];
int dis[N][N];

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

    cin >> n >> m;
    vector<string> a(n);
    for(int i = 0; i<n; ++i) cin >> a[i];

    for(int i = 0; i<n; ++i) for(int j = 0; j<m; ++j) if (a[i][j] == 'R') grid[i+1][j+1] = 1;
        else if (a[i][j] == 'F') grid[i+1][j+1] = 2;

    memset(dis, 63, sizeof dis);
    deque<pair<int, int>> q; q.push_back({1, 1});
    dis[1][1] = 1;

    int ans = 1;
    while(q.size()){
        pair<int, int> u = q.front(); q.pop_front();
        maximize(ans, dis[u.first][u.second]);
        for(int dir = 0; dir < 4; ++dir){
            pair<int, int> v = {u.first + dx[dir], u.second + dy[dir]};
            if (grid[v.first][v.second] == 0) continue;
            if (grid[v.first][v.second] != grid[u.first][u.second]){
                if (minimize(dis[v.first][v.second], dis[u.first][u.second] + 1)){
                    q.push_back(v);
                }
            }
            else{
                if (minimize(dis[v.first][v.second], dis[u.first][u.second])){
                    q.push_front(v);
                }
            }
        }
    }

    cout << ans << "\n";


    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 72784 KB Output is correct
2 Correct 8 ms 64092 KB Output is correct
3 Correct 9 ms 64220 KB Output is correct
4 Correct 15 ms 72796 KB Output is correct
5 Correct 10 ms 68444 KB Output is correct
6 Correct 8 ms 64224 KB Output is correct
7 Correct 8 ms 64092 KB Output is correct
8 Correct 9 ms 66204 KB Output is correct
9 Correct 9 ms 66140 KB Output is correct
10 Correct 10 ms 68432 KB Output is correct
11 Correct 11 ms 68440 KB Output is correct
12 Correct 14 ms 68456 KB Output is correct
13 Correct 10 ms 68444 KB Output is correct
14 Correct 10 ms 68444 KB Output is correct
15 Correct 18 ms 72952 KB Output is correct
16 Correct 23 ms 72796 KB Output is correct
17 Correct 17 ms 72788 KB Output is correct
18 Correct 15 ms 72976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 123888 KB Output is correct
2 Correct 44 ms 87732 KB Output is correct
3 Correct 171 ms 159296 KB Output is correct
4 Correct 58 ms 100584 KB Output is correct
5 Correct 82 ms 129824 KB Output is correct
6 Correct 573 ms 172748 KB Output is correct
7 Correct 17 ms 126044 KB Output is correct
8 Correct 16 ms 123740 KB Output is correct
9 Correct 9 ms 64344 KB Output is correct
10 Correct 8 ms 64152 KB Output is correct
11 Correct 15 ms 125788 KB Output is correct
12 Correct 9 ms 66264 KB Output is correct
13 Correct 42 ms 87900 KB Output is correct
14 Correct 27 ms 80476 KB Output is correct
15 Correct 21 ms 82512 KB Output is correct
16 Correct 25 ms 71516 KB Output is correct
17 Correct 88 ms 103344 KB Output is correct
18 Correct 67 ms 103212 KB Output is correct
19 Correct 54 ms 100488 KB Output is correct
20 Correct 48 ms 97972 KB Output is correct
21 Correct 121 ms 132688 KB Output is correct
22 Correct 83 ms 129872 KB Output is correct
23 Correct 168 ms 119124 KB Output is correct
24 Correct 95 ms 132228 KB Output is correct
25 Correct 302 ms 159548 KB Output is correct
26 Correct 377 ms 195152 KB Output is correct
27 Correct 460 ms 177916 KB Output is correct
28 Correct 533 ms 172848 KB Output is correct
29 Correct 558 ms 170444 KB Output is correct
30 Correct 461 ms 175824 KB Output is correct
31 Correct 469 ms 137272 KB Output is correct
32 Correct 381 ms 176584 KB Output is correct