답안 #769766

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
769766 2023-06-30T08:33:21 Z Ellinor Tracks in the Snow (BOI13_tracks) C++14
84.6875 / 100
1751 ms 1048576 KB
    #include <bits/stdc++.h>
    using namespace std;
     
    #define rep(i,a,b) for(int i = (a); i < (b); i++)
    typedef long long ll;
     
    int H, W;
    vector<string> grid;
     
    vector<vector<ll>> visited; // bitset ?
     
    //priority_queue<vector<ll>> q;
    vector<vector<pair<ll, ll>>> pq_vec;
     
    void dfs(int hat, int wat, ll num)
    {
        if (visited[hat][wat]>0) return;
        if (grid[hat][wat] == '.') return;
        visited[hat][wat] = num;
     
        char ch = grid[hat][wat];
        if (hat + 1 < H) {
            if (grid[hat + 1][wat] == ch) pq_vec[num].push_back({hat + 1, wat});
            else pq_vec[num + 1].push_back({hat + 1, wat});
        }
        if (wat + 1 < W) {
            if (grid[hat][wat + 1] == ch) pq_vec[num].push_back({hat, wat + 1});
            else pq_vec[num + 1].push_back({hat, wat + 1});
        }
        if (hat - 1 >= 0) {
            if (grid[hat - 1][wat] == ch) pq_vec[num].push_back({hat - 1, wat});
            else pq_vec[num + 1].push_back({hat - 1, wat});
        }
        if (wat - 1 >= 0) {
            if (grid[hat][wat - 1] == ch) pq_vec[num].push_back({hat, wat - 1});
            else pq_vec[num + 1].push_back({hat, wat - 1});
        }
    }
     
    int32_t main()
    {
        cin>>H>>W;
        grid.assign(H, "");
        rep(i,0,H){
            cin>>grid[i];
        }
     
        visited.assign(H, vector<ll>(W, -1));
        //q.push({-1,0,0});
        pq_vec.assign(H*W + 1, {});
        pq_vec[1].push_back({0,0});

        ll i = 1;
        while(i < pq_vec.size())
        {
            ll j = 0;
            while (j < pq_vec[i].size())
            {
                pair<ll,ll> x = pq_vec[i][j];
                dfs(x.first, x.second, i);
                j++;
            }
            i++;
        }
     
        ll ans = 1;
        rep(i,0,H){
            rep(j,0,W){
                ans = max(ans, visited[i][j]);
            }
        }
        cout << ans;
    }

Compilation message

tracks.cpp: In function 'int32_t main()':
tracks.cpp:54:17: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::vector<std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |         while(i < pq_vec.size())
      |               ~~^~~~~~~~~~~~~~~
tracks.cpp:57:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |             while (j < pq_vec[i].size())
      |                    ~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 23408 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 22 ms 20772 KB Output is correct
5 Correct 5 ms 4656 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 816 KB Output is correct
9 Correct 1 ms 724 KB Output is correct
10 Correct 5 ms 4416 KB Output is correct
11 Correct 6 ms 5768 KB Output is correct
12 Correct 11 ms 8480 KB Output is correct
13 Correct 5 ms 4660 KB Output is correct
14 Correct 5 ms 4564 KB Output is correct
15 Correct 28 ms 20552 KB Output is correct
16 Correct 34 ms 23424 KB Output is correct
17 Correct 20 ms 15408 KB Output is correct
18 Correct 27 ms 20680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 3156 KB Output is correct
2 Correct 128 ms 95772 KB Output is correct
3 Correct 1039 ms 876108 KB Output is correct
4 Correct 212 ms 165520 KB Output is correct
5 Correct 843 ms 647892 KB Output is correct
6 Runtime error 1496 ms 1048576 KB Execution killed with signal 9
7 Correct 4 ms 2900 KB Output is correct
8 Correct 5 ms 3124 KB Output is correct
9 Correct 6 ms 4480 KB Output is correct
10 Correct 2 ms 2004 KB Output is correct
11 Correct 3 ms 2644 KB Output is correct
12 Correct 3 ms 1844 KB Output is correct
13 Correct 134 ms 95644 KB Output is correct
14 Correct 76 ms 56660 KB Output is correct
15 Correct 80 ms 59124 KB Output is correct
16 Correct 62 ms 45640 KB Output is correct
17 Correct 358 ms 244052 KB Output is correct
18 Correct 309 ms 230620 KB Output is correct
19 Correct 214 ms 164720 KB Output is correct
20 Correct 226 ms 195700 KB Output is correct
21 Correct 584 ms 509736 KB Output is correct
22 Correct 849 ms 647876 KB Output is correct
23 Correct 703 ms 466588 KB Output is correct
24 Correct 698 ms 559104 KB Output is correct
25 Correct 1407 ms 928756 KB Output is correct
26 Runtime error 1214 ms 1048576 KB Execution killed with signal 9
27 Runtime error 922 ms 1048576 KB Execution killed with signal 9
28 Runtime error 1456 ms 1048576 KB Execution killed with signal 9
29 Runtime error 1403 ms 1048576 KB Execution killed with signal 9
30 Runtime error 1549 ms 1048576 KB Execution killed with signal 9
31 Correct 1751 ms 976460 KB Output is correct
32 Runtime error 981 ms 1048576 KB Execution killed with signal 9