Submission #1292159

#TimeUsernameProblemLanguageResultExecution timeMemory
1292159sitingfakeMecho (IOI09_mecho)C++20
100 / 100
127 ms6384 KiB
#include<bits/stdc++.h>
using namespace std;

// define

#define execute cerr << " Time: " << fixed << setprecision(6) << (1.0 * clock() / CLOCKS_PER_SEC) << "s\n";
#define ll long long
#define ii pair <int , int>
#define iii pair <int , ii>
#define se second
#define fi first
#define all(v) (v).begin() , (v).end()
#define Unique(v) sort(all(v)) , v.resize(unique(all(v)) - v.begin())
#define bit(x,i) (((x) >> (i)) & 1LL)
#define flip(x,i) ((x) ^ (1LL << (i)))
#define ms(d,x) memset(d , x , sizeof(d))
#define exist __exist
#define ends __ends
#define visit visited
#define left __left
#define right __right
#define prev __prev
#define next __next
#define sitingfake 1
#define orz 1
//constant

const long long mod = 1e9 + 7;
const long long linf = 4557430888798830399LL;
const long long nlinf = -4485090715960753727LL;
const int inf = 1061109567;
const int ninf = -1044266559;
const int dx[] = {0 , -1 , 0 , 1};
const int dy[] = {-1 , 0 , 1 , 0};

template<typename T> bool maximize(T &a, const T &b)
{
    if(a < b) {a = b; return 1;}
    return 0;
}

template<typename T> bool minimize(T &a, const T &b)
{
    if(a > b) {a = b; return 1;}
    return 0;
}

void Plus(ll & a ,ll b)
{
    b %= mod;
    a += b;
    if(a < 0) a += mod;
    a %= mod;
    return;
}

void Mul(ll & a, ll b)
{
    (a *= (b % mod)) %= mod;
    return;
}

//code
const int maxn = 808;

char a[maxn][maxn];

ii st , fin;

int n , S;

vector <ii> Bee;

int distBee[maxn][maxn];

int dist[maxn][maxn];

bool check(int eat)
{
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            dist[i][j] = inf;
        }
    }
    queue <ii> q;

    dist[st.fi][st.se] = 0;
    q.push(st);

    while(!q.empty())
    {
        int u = q.front().fi;
        int v = q.front().se;
        //cout << u << " " << v << endl;
        q.pop();

        for(int i = 0 ; i < 4; i++)
        {
            int x = u + dx[i];
            int y = v + dy[i];
            if(1 <= x && x <= n && 1 <= y && y <= n && a[x][y] != 'T')
            {
                if(((dist[u][v] + 1) / S) < distBee[x][y] - eat && minimize(dist[x][y] , dist[u][v] + 1))
                {
                    q.push({x , y});
                }
            }
        }
    }
    for(int i = 0; i < 4; i++)
    {
        int u = dx[i] + fin.fi;
        int v = dy[i] + fin.se;
        if(1 <= u && u <= n && 1 <= v && v <= n && a[u][v] != 'T' && dist[u][v] != inf)
        {
            return 1;
        }
    }

    return 0;
}
void solve(void)
{
    cin >> n >> S;

    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            cin >> a[i][j];
            if(a[i][j] == 'M') st = ii(i , j);
            else if(a[i][j] == 'D') fin = ii(i , j);
            else if(a[i][j] == 'H') Bee.push_back({i , j});
        }
    }

    ms(distBee , 0x3f);
    queue <ii> q;
    for(ii i : Bee) distBee[i.fi][i.se] = 0 , q.push(i);
    while(!q.empty())
    {
        int u = q.front().fi;
        int v = q.front().se;
        q.pop();
        for(int i = 0; i < 4; i++)
        {
            int x = u + dx[i];
            int y = v + dy[i];
            if(1 <= x && x <= n && 1 <= y && y <= n && a[x][y] != 'T' && a[x][y] != 'D')
            {
                if(minimize(distBee[x][y] , distBee[u][v] + 1))
                {
                    q.push({x , y});
                }
            }
        }
    }
    int left = 0 , right = distBee[st.fi][st.se] - 1 ,ans = -1;
    while(left <= right)
    {
        int mid = (left + right) >> 1;

        if(check(mid))
        {
            ans = mid;
            left = mid + 1;
        }
        else right = mid - 1;

    }

    cout << ans;
}

/**
**/
signed main()
{
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);

   #define task ""

   if(fopen(task".inp","r"))
   {
       freopen(task".inp","r",stdin);
       freopen(task".out","w",stdout);
   }

   int tc = 1;
//   cin >> tc;
   while(tc--) solve();

//   execute;
}

Compilation message (stderr)

mecho.cpp: In function 'int main()':
mecho.cpp:189:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  189 |        freopen(task".inp","r",stdin);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
mecho.cpp:190:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  190 |        freopen(task".out","w",stdout);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...