Submission #841189

# Submission time Handle Problem Language Result Execution time Memory
841189 2023-09-01T10:44:40 Z daoda Mecho (IOI09_mecho) C++17
100 / 100
299 ms 3280 KB
#include <bits/stdc++.h>

using namespace std;
#define FOR(a, b) for(ll i = a; i < b; i++)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);

typedef long long int ll;
typedef pair<ll, ll> pll; // comments that are mixed
typedef vector<ll> vll; // in with code are placed
typedef vector<pll> vpll; // on the right side
typedef vector<bool> vb;

struct Object {
    ll row,col;
    char type='H';
};

ll n,s;
vector<vector<char>> grid, stat; 
vll dr={0,0,-1,1}, dc={-1, 1, 0, 0};
vector<Object> hives;
Object bear, home;

void bfs(queue<Object>&bfs_list,function<bool(char&,char&)> cond,char rep,ll iters = 1){
    FOR(0, iters) {
        
        ll sz=bfs_list.size();
        
        FOR(0, sz) {
            
            Object cur=bfs_list.front();
            bfs_list.pop();
            
            FOR(0, 4) {
                
                char& cell = stat[cur.row + dr[i]][cur.col + dc[i]];
                if(cond(stat[cur.row][cur.col], cell)) {
                    cell=rep;
                    bfs_list.push((Object){.row=cur.row+dr[i],.col=cur.col+dc[i]});
                }
            }
        }
    }
}

bool cond1(char& a,char& b) { return (b == 'G' || b == 'M'); }
bool cond2(char& a,char& b) { return (a == 'M' && (b == 'G' || b== 'D')); }

bool f(ll max_t) {
    stat=grid;
    
    queue<Object> bfs_list1, bfs_list2;
    
    FOR(0, hives.size()) bfs_list1.push(hives[i]);
    bfs_list2.push(bear);
    
    
    
    bfs(bfs_list1,cond1,'H',max_t);
    
    while(bfs_list2.size()) {
       bfs(bfs_list2,cond2,'M', s);
       if(stat[home.row][home.col] == 'M') return true;
       bfs(bfs_list1,cond1,'H', 1);
    }
    
    return false;
}

int main() {
    fast

    cin >> n >> s;
    grid.resize(n+2, vector<char>(n+2, 'T'));
    
    
    FOR(1, n+1) {
        for(ll i2=1; i2 < n+1; i2++) {
            cin >> grid[i][i2];
            if(grid[i][i2] == 'H') hives.push_back((Object){.row=i,.col=i2});
            if(grid[i][i2] == 'M') bear = (Object){.row=i,.col=i2,.type='M'};
            if(grid[i][i2] == 'D') home = (Object){.row=i,.col=i2,.type='D'};
        }
    }

    ll lb=-1, upb=n*n;
    while(lb < upb) {
        ll mid=(lb + upb + 1) /2 ;
        if(f(mid)) lb=mid;
        else upb = mid - 1 ;
    }
    cout << lb;

    return 0;
}

Compilation message

mecho.cpp: In function 'bool f(ll)':
mecho.cpp:4:35: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<Object>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define FOR(a, b) for(ll i = a; i < b; i++)
      |                                 ~~^~~~~~~~~
    5 | #define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    6 | 
      |                                    
    7 | typedef long long int ll;
      | ~~~~~~~~~~~~~~~~~~~~~~~~~          
    8 | typedef pair<ll, ll> pll; // comments that are mixed
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    9 | typedef vector<ll> vll; // in with code are placed
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   10 | typedef vector<pll> vpll; // on the right side
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   11 | typedef vector<bool> vb;
      | ~~~~~~~~~~~~~~~~~~~~~~~~           
   12 | 
      |                                    
   13 | struct Object {
      | ~~~~~~~~~~~~~~~                    
   14 |     ll row,col;
      |     ~~~~~~~~~~~                    
   15 |     char type='H';
      |     ~~~~~~~~~~~~~~                 
   16 | };
      | ~~                                 
   17 | 
      |                                    
   18 | ll n,s;
      | ~~~~~~~                            
   19 | vector<vector<char>> grid, stat;
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~   
   20 | vll dr={0,0,-1,1}, dc={-1, 1, 0, 0};
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   21 | vector<Object> hives;
      | ~~~~~~~~~~~~~~~~~~~~~              
   22 | Object bear, home;
      | ~~~~~~~~~~~~~~~~~~                 
   23 | 
      |                                    
   24 | void bfs(queue<Object>&bfs_list,function<bool(char&,char&)> cond,char rep,ll iters = 1){
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   25 |     FOR(0, iters) {
      |     ~~~~~~~~~~~~~~~                
   26 | 
      |                                    
   27 |         ll sz=bfs_list.size();
      |         ~~~~~~~~~~~~~~~~~~~~~~     
   28 | 
      |                                    
   29 |         FOR(0, sz) {
      |         ~~~~~~~~~~~~               
   30 | 
      |                                    
   31 |             Object cur=bfs_list.front();
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   32 |             bfs_list.pop();
      |             ~~~~~~~~~~~~~~~        
   33 | 
      |                                    
   34 |             FOR(0, 4) {
      |             ~~~~~~~~~~~            
   35 | 
      |                                    
   36 |                 char& cell = stat[cur.row + dr[i]][cur.col + dc[i]];
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   37 |                 if(cond(stat[cur.row][cur.col], cell)) {
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   38 |                     cell=rep;
      |                     ~~~~~~~~~      
   39 |                     bfs_list.push((Object){.row=cur.row+dr[i],.col=cur.col+dc[i]});
      |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   40 |                 }
      |                 ~                  
   41 |             }
      |             ~                      
   42 |         }
      |         ~                          
   43 |     }
      |     ~                              
   44 | }
      | ~                                  
   45 | 
      |                                    
   46 | bool cond1(char& a,char& b) { return (b == 'G' || b == 'M'); }
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   47 | bool cond2(char& a,char& b) { return (a == 'M' && (b == 'G' || b== 'D')); }
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   48 | 
      |                                    
   49 | bool f(ll max_t) {
      | ~~~~~~~~~~~~~~~~~~                 
   50 |     stat=grid;
      |     ~~~~~~~~~~                     
   51 | 
      |                                    
   52 |     queue<Object> bfs_list1, bfs_list2;
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   53 | 
      |                                    
   54 |     FOR(0, hives.size()) bfs_list1.push(hives[i]);
      |     ~~~~~~~~~~~~~~~~~~~            
mecho.cpp:54:5: note: in expansion of macro 'FOR'
   54 |     FOR(0, hives.size()) bfs_list1.push(hives[i]);
      |     ^~~
# Verdict Execution time Memory 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 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 265 ms 2520 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 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 2 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 256 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 308 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 22 ms 596 KB Output is correct
34 Correct 21 ms 596 KB Output is correct
35 Correct 30 ms 596 KB Output is correct
36 Correct 28 ms 724 KB Output is correct
37 Correct 28 ms 848 KB Output is correct
38 Correct 39 ms 724 KB Output is correct
39 Correct 41 ms 932 KB Output is correct
40 Correct 36 ms 852 KB Output is correct
41 Correct 53 ms 852 KB Output is correct
42 Correct 52 ms 980 KB Output is correct
43 Correct 44 ms 980 KB Output is correct
44 Correct 72 ms 1156 KB Output is correct
45 Correct 58 ms 1236 KB Output is correct
46 Correct 53 ms 1236 KB Output is correct
47 Correct 76 ms 1236 KB Output is correct
48 Correct 65 ms 1424 KB Output is correct
49 Correct 73 ms 1424 KB Output is correct
50 Correct 91 ms 1364 KB Output is correct
51 Correct 82 ms 1620 KB Output is correct
52 Correct 79 ms 1620 KB Output is correct
53 Correct 113 ms 1628 KB Output is correct
54 Correct 99 ms 1816 KB Output is correct
55 Correct 90 ms 1748 KB Output is correct
56 Correct 133 ms 1824 KB Output is correct
57 Correct 108 ms 2024 KB Output is correct
58 Correct 105 ms 2016 KB Output is correct
59 Correct 157 ms 2048 KB Output is correct
60 Correct 135 ms 2308 KB Output is correct
61 Correct 119 ms 2260 KB Output is correct
62 Correct 180 ms 2288 KB Output is correct
63 Correct 214 ms 2384 KB Output is correct
64 Correct 231 ms 2280 KB Output is correct
65 Correct 214 ms 2284 KB Output is correct
66 Correct 245 ms 2284 KB Output is correct
67 Correct 223 ms 2388 KB Output is correct
68 Correct 221 ms 2260 KB Output is correct
69 Correct 197 ms 2260 KB Output is correct
70 Correct 206 ms 2384 KB Output is correct
71 Correct 235 ms 2388 KB Output is correct
72 Correct 248 ms 2356 KB Output is correct
73 Correct 224 ms 3280 KB Output is correct
74 Correct 279 ms 3156 KB Output is correct
75 Correct 299 ms 3156 KB Output is correct
76 Correct 299 ms 3156 KB Output is correct
77 Correct 291 ms 3196 KB Output is correct
78 Correct 271 ms 3152 KB Output is correct
79 Correct 265 ms 3048 KB Output is correct
80 Correct 278 ms 3028 KB Output is correct
81 Correct 272 ms 3036 KB Output is correct
82 Correct 294 ms 3112 KB Output is correct
83 Correct 263 ms 2900 KB Output is correct
84 Correct 271 ms 2900 KB Output is correct
85 Correct 283 ms 2916 KB Output is correct
86 Correct 268 ms 2900 KB Output is correct
87 Correct 264 ms 3136 KB Output is correct
88 Correct 258 ms 2772 KB Output is correct
89 Correct 256 ms 2752 KB Output is correct
90 Correct 282 ms 2772 KB Output is correct
91 Correct 266 ms 2776 KB Output is correct
92 Correct 269 ms 2772 KB Output is correct