답안 #736327

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
736327 2023-05-05T12:50:16 Z Cookie Maze (JOI23_ho_t3) C++14
8 / 100
1453 ms 226592 KB
#include<bits/stdc++.h>
#include<fstream>
using namespace std;
ifstream fin("WINTER.inp");
ofstream fout("WINTER.out");
 
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
const ld PI = 3.14159265359;
const int x[4] = {1, -1, 0, 0};
const int y[4] = {0, 0, 1, -1};
const ll mod = 1e9 + 7;
const int mxn = 5e5, mxm = 1e5, sq = 400;
const int base = (1 << 18);
const ll inf = 1e9;
const ld pre = 1e-6;
int r, c, n, sti, stj, eni, enj;
vt<vt<char>>a;
vt<vt<int>>d;
vt<set<int>>row, col;
bool inside(int i, int j){
    return(i >= 1 && j >= 1 && i <= r && j <= c);
}
signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> r >> c >> n;
    a.resize(r + 1, vt<char>(c + 1));
    d.resize(r + 1, vt<int>(c + 1));
   
    cin >> sti >> stj >> eni >> enj;
    row.resize(r + 1); col.resize(c + 1);
    forr(i, 1, r + 1){
        forr(j, 1, c + 1){
            cin >> a[i][j]; d[i][j] = 1e9;
            row[i].insert(j); col[j].insert(i);
        }
    }
    
    deque<pair<int, int>>dq; dq.pb({sti, stj});
    d[sti][stj] = 0;
    while(!dq.empty()){
        auto [i, j] = dq.front(); dq.pop_front();
        
        if(a[i][j] == '.'){
        for(int t = 0; t < 4; t++){
            int nwi = i + x[t], nwj = j + y[t];
            if(inside(nwi, nwj)){
                if(d[nwi][nwj] > d[i][j]){
                    d[nwi][nwj] = d[i][j];
                    dq.push_front({nwi, nwj});
                }
            }
        }
        }
        for(auto ii: {i - n, i + n}){
            vt<int>rem;
            if(!inside(ii, 1))continue;
            auto it = row[ii].lower_bound(j - n + 1), it2 = row[ii].upper_bound(j + n - 1);
            if(it == row[ii].end())continue;
            for(auto iter = it; iter != it2; iter++){
                int jj = *iter;
                if(d[ii][jj] > d[i][j] + 1){
                        d[ii][jj] = d[i][j] + 1;
                        dq.push_back({ii, jj});
                }
                rem.pb(jj);
            }
            for(auto jj: rem){
                row[ii].erase(jj); col[jj].erase(ii);
            }
            for(int jj = 1; jj < rem.size(); jj++){
                assert(rem[jj] == rem[jj - 1]);
            }
        }
        for(auto jj : {j - n, j + n}){
            vt<int>rem;
            if(!inside(1, jj))continue;
            auto it = col[jj].lower_bound(i - n + 1), it2 = col[jj].upper_bound(i + n - 1);
            if(it == col[jj].end())continue;
            for(auto iter = it; iter != it2; iter++){
                int ii = *iter;
                if(d[ii][jj] > d[i][j] + 1){
                        d[ii][jj] = d[i][j] + 1;
                        dq.push_back({ii, jj});
                }
                rem.pb(ii);
            }
            for(auto ii: rem){
                row[ii].erase(jj); col[jj].erase(ii);
            }
        }
    }
    int ans = 1e9;
    for(int i = eni - n + 1; i <= eni + n - 1; i++){
        for(int j = enj - n + 1; j  <= enj + n - 1; j++){
            if(inside(i, j)){
                
                ans = min(ans, d[i][j] + 1);
            }
        }
    }
    ans = min(ans, d[eni][enj]);
    cout << ans;
    return(0);
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:51:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   51 |         auto [i, j] = dq.front(); dq.pop_front();
      |              ^
Main.cpp:80:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |             for(int jj = 1; jj < rem.size(); jj++){
      |                             ~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 37 ms 6228 KB Output is correct
20 Correct 23 ms 7224 KB Output is correct
21 Correct 27 ms 6268 KB Output is correct
22 Correct 40 ms 6364 KB Output is correct
23 Correct 39 ms 6328 KB Output is correct
24 Correct 29 ms 9368 KB Output is correct
25 Correct 28 ms 9448 KB Output is correct
26 Correct 41 ms 6228 KB Output is correct
27 Correct 43 ms 6312 KB Output is correct
28 Correct 33 ms 6228 KB Output is correct
29 Correct 92 ms 15220 KB Output is correct
30 Correct 37 ms 7964 KB Output is correct
31 Correct 72 ms 15112 KB Output is correct
32 Correct 104 ms 15380 KB Output is correct
33 Correct 96 ms 15180 KB Output is correct
34 Correct 72 ms 22872 KB Output is correct
35 Correct 73 ms 22864 KB Output is correct
36 Correct 111 ms 15336 KB Output is correct
37 Correct 107 ms 15256 KB Output is correct
38 Correct 90 ms 15312 KB Output is correct
39 Correct 1159 ms 148944 KB Output is correct
40 Correct 118 ms 17628 KB Output is correct
41 Correct 94 ms 28076 KB Output is correct
42 Correct 141 ms 21576 KB Output is correct
43 Correct 150 ms 30624 KB Output is correct
44 Correct 597 ms 80168 KB Output is correct
45 Correct 535 ms 88164 KB Output is correct
46 Correct 783 ms 148936 KB Output is correct
47 Correct 1209 ms 149000 KB Output is correct
48 Correct 1403 ms 149356 KB Output is correct
49 Correct 959 ms 226508 KB Output is correct
50 Correct 938 ms 226592 KB Output is correct
51 Correct 1277 ms 148824 KB Output is correct
52 Correct 1334 ms 148940 KB Output is correct
53 Correct 1453 ms 148940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Runtime error 1 ms 596 KB Execution killed with signal 6
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Runtime error 1 ms 596 KB Execution killed with signal 6
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Runtime error 1 ms 596 KB Execution killed with signal 6
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Runtime error 1 ms 596 KB Execution killed with signal 6
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 37 ms 6228 KB Output is correct
20 Correct 23 ms 7224 KB Output is correct
21 Correct 27 ms 6268 KB Output is correct
22 Correct 40 ms 6364 KB Output is correct
23 Correct 39 ms 6328 KB Output is correct
24 Correct 29 ms 9368 KB Output is correct
25 Correct 28 ms 9448 KB Output is correct
26 Correct 41 ms 6228 KB Output is correct
27 Correct 43 ms 6312 KB Output is correct
28 Correct 33 ms 6228 KB Output is correct
29 Correct 92 ms 15220 KB Output is correct
30 Correct 37 ms 7964 KB Output is correct
31 Correct 72 ms 15112 KB Output is correct
32 Correct 104 ms 15380 KB Output is correct
33 Correct 96 ms 15180 KB Output is correct
34 Correct 72 ms 22872 KB Output is correct
35 Correct 73 ms 22864 KB Output is correct
36 Correct 111 ms 15336 KB Output is correct
37 Correct 107 ms 15256 KB Output is correct
38 Correct 90 ms 15312 KB Output is correct
39 Correct 1159 ms 148944 KB Output is correct
40 Correct 118 ms 17628 KB Output is correct
41 Correct 94 ms 28076 KB Output is correct
42 Correct 141 ms 21576 KB Output is correct
43 Correct 150 ms 30624 KB Output is correct
44 Correct 597 ms 80168 KB Output is correct
45 Correct 535 ms 88164 KB Output is correct
46 Correct 783 ms 148936 KB Output is correct
47 Correct 1209 ms 149000 KB Output is correct
48 Correct 1403 ms 149356 KB Output is correct
49 Correct 959 ms 226508 KB Output is correct
50 Correct 938 ms 226592 KB Output is correct
51 Correct 1277 ms 148824 KB Output is correct
52 Correct 1334 ms 148940 KB Output is correct
53 Correct 1453 ms 148940 KB Output is correct
54 Correct 0 ms 212 KB Output is correct
55 Correct 0 ms 212 KB Output is correct
56 Correct 0 ms 212 KB Output is correct
57 Correct 0 ms 212 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 1 ms 212 KB Output is correct
61 Correct 1 ms 340 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 1 ms 468 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 1 ms 340 KB Output is correct
66 Correct 1 ms 340 KB Output is correct
67 Correct 1 ms 340 KB Output is correct
68 Correct 1 ms 468 KB Output is correct
69 Correct 1 ms 468 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
71 Correct 1 ms 212 KB Output is correct
72 Runtime error 1 ms 596 KB Execution killed with signal 6
73 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 37 ms 6228 KB Output is correct
20 Correct 23 ms 7224 KB Output is correct
21 Correct 27 ms 6268 KB Output is correct
22 Correct 40 ms 6364 KB Output is correct
23 Correct 39 ms 6328 KB Output is correct
24 Correct 29 ms 9368 KB Output is correct
25 Correct 28 ms 9448 KB Output is correct
26 Correct 41 ms 6228 KB Output is correct
27 Correct 43 ms 6312 KB Output is correct
28 Correct 33 ms 6228 KB Output is correct
29 Correct 92 ms 15220 KB Output is correct
30 Correct 37 ms 7964 KB Output is correct
31 Correct 72 ms 15112 KB Output is correct
32 Correct 104 ms 15380 KB Output is correct
33 Correct 96 ms 15180 KB Output is correct
34 Correct 72 ms 22872 KB Output is correct
35 Correct 73 ms 22864 KB Output is correct
36 Correct 111 ms 15336 KB Output is correct
37 Correct 107 ms 15256 KB Output is correct
38 Correct 90 ms 15312 KB Output is correct
39 Correct 1159 ms 148944 KB Output is correct
40 Correct 118 ms 17628 KB Output is correct
41 Correct 94 ms 28076 KB Output is correct
42 Correct 141 ms 21576 KB Output is correct
43 Correct 150 ms 30624 KB Output is correct
44 Correct 597 ms 80168 KB Output is correct
45 Correct 535 ms 88164 KB Output is correct
46 Correct 783 ms 148936 KB Output is correct
47 Correct 1209 ms 149000 KB Output is correct
48 Correct 1403 ms 149356 KB Output is correct
49 Correct 959 ms 226508 KB Output is correct
50 Correct 938 ms 226592 KB Output is correct
51 Correct 1277 ms 148824 KB Output is correct
52 Correct 1334 ms 148940 KB Output is correct
53 Correct 1453 ms 148940 KB Output is correct
54 Correct 0 ms 212 KB Output is correct
55 Correct 0 ms 212 KB Output is correct
56 Correct 0 ms 212 KB Output is correct
57 Correct 0 ms 212 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 1 ms 212 KB Output is correct
61 Correct 1 ms 340 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 1 ms 468 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 1 ms 340 KB Output is correct
66 Correct 1 ms 340 KB Output is correct
67 Correct 1 ms 340 KB Output is correct
68 Correct 1 ms 468 KB Output is correct
69 Correct 1 ms 468 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
71 Correct 1 ms 212 KB Output is correct
72 Runtime error 1 ms 596 KB Execution killed with signal 6
73 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 37 ms 6228 KB Output is correct
20 Correct 23 ms 7224 KB Output is correct
21 Correct 27 ms 6268 KB Output is correct
22 Correct 40 ms 6364 KB Output is correct
23 Correct 39 ms 6328 KB Output is correct
24 Correct 29 ms 9368 KB Output is correct
25 Correct 28 ms 9448 KB Output is correct
26 Correct 41 ms 6228 KB Output is correct
27 Correct 43 ms 6312 KB Output is correct
28 Correct 33 ms 6228 KB Output is correct
29 Correct 92 ms 15220 KB Output is correct
30 Correct 37 ms 7964 KB Output is correct
31 Correct 72 ms 15112 KB Output is correct
32 Correct 104 ms 15380 KB Output is correct
33 Correct 96 ms 15180 KB Output is correct
34 Correct 72 ms 22872 KB Output is correct
35 Correct 73 ms 22864 KB Output is correct
36 Correct 111 ms 15336 KB Output is correct
37 Correct 107 ms 15256 KB Output is correct
38 Correct 90 ms 15312 KB Output is correct
39 Correct 1159 ms 148944 KB Output is correct
40 Correct 118 ms 17628 KB Output is correct
41 Correct 94 ms 28076 KB Output is correct
42 Correct 141 ms 21576 KB Output is correct
43 Correct 150 ms 30624 KB Output is correct
44 Correct 597 ms 80168 KB Output is correct
45 Correct 535 ms 88164 KB Output is correct
46 Correct 783 ms 148936 KB Output is correct
47 Correct 1209 ms 149000 KB Output is correct
48 Correct 1403 ms 149356 KB Output is correct
49 Correct 959 ms 226508 KB Output is correct
50 Correct 938 ms 226592 KB Output is correct
51 Correct 1277 ms 148824 KB Output is correct
52 Correct 1334 ms 148940 KB Output is correct
53 Correct 1453 ms 148940 KB Output is correct
54 Correct 0 ms 212 KB Output is correct
55 Correct 0 ms 212 KB Output is correct
56 Correct 0 ms 212 KB Output is correct
57 Correct 0 ms 212 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 1 ms 212 KB Output is correct
61 Correct 1 ms 340 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 1 ms 468 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 1 ms 340 KB Output is correct
66 Correct 1 ms 340 KB Output is correct
67 Correct 1 ms 340 KB Output is correct
68 Correct 1 ms 468 KB Output is correct
69 Correct 1 ms 468 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
71 Correct 1 ms 212 KB Output is correct
72 Runtime error 1 ms 596 KB Execution killed with signal 6
73 Halted 0 ms 0 KB -