From a874c06b3f162fd566238e8d6f5174100ce2a40c Mon Sep 17 00:00:00 2001 From: rajcode126 <93469376+rajcode126@users.noreply.github.com> Date: Mon, 31 Oct 2022 23:46:10 +0530 Subject: [PATCH] Delete GMNT.cpp --- GMNT.cpp | 235 ------------------------------------------------------- 1 file changed, 235 deletions(-) delete mode 100644 GMNT.cpp diff --git a/GMNT.cpp b/GMNT.cpp deleted file mode 100644 index ab6cb6b3..00000000 --- a/GMNT.cpp +++ /dev/null @@ -1,235 +0,0 @@ -/*/ Author: iamshubh69 /*/ -// #pragma GCC optimize ("O3") -#include "bits/stdc++.h" -#include "ext/pb_ds/assoc_container.hpp" -#include "ext/pb_ds/tree_policy.hpp" -using namespace std; -using namespace __gnu_pbds; - -template -using ordered_set = tree, rb_tree_tag, tree_order_statistics_node_update> ; - -template> -using ordered_map = tree; -// find_by_order(k) returns iterator to kth element starting from 0; -// order_of_key(k) returns count of elements strictly smaller than k; - -template -using min_heap = priority_queue,greater >; - -/*/---------------------------IO(Debugging)----------------------/*/ - -template::value, typename T_container::value_type>::type> -istream& operator >> (istream &is, T_container &v) { - for(T &x : v) is >> x; return is; -} -#ifdef __SIZEOF_INT128__ -ostream& operator << (ostream &os, __int128 const& value){ - static char buffer[64]; - int index = 0; - __uint128_t T = (value < 0) ? (-(value + 1)) + __uint128_t(1) : value; - if (value < 0) - os << '-'; - else if (T == 0) - return os << '0'; - for(; T > 0; ++index){ - buffer[index] = static_cast('0' + (T % 10)); - T /= 10; - } - while(index > 0) - os << buffer[--index]; - return os; -} -istream& operator >> (istream& is, __int128& T){ - static char buffer[64]; - is >> buffer; - size_t len = strlen(buffer), index = 0; - T = 0; int mul = 1; - if (buffer[index] == '-') - ++index, mul *= -1; - for(; index < len; ++index) - T = T * 10 + static_cast(buffer[index] - '0'); - T *= mul; - return is; -} -#endif - -template -ostream& operator<<(ostream &os, const pair &p) { - return os << '(' << p.first << ", " << p.second << ')'; -} - -template::value, typename T_container::value_type>::type> -ostream& operator << (ostream &os, const T_container &v) { - os << '{'; string sep; - for (const T &x : v) os << sep << x, sep = ", "; - return os << '}'; -} -template, class R = less

> ostream& operator << (ostream& out, priority_queue const& M){ - static priority_queue U; - U = M; - out << "{ "; - while(!U.empty()) - out << U.top() << " ", U.pop(); - return (out << "}"); -} -template ostream& operator << (ostream& out, queue

const& M){ - static queue

U; - U = M; - out << "{"; string sep; - while(!U.empty()){ - out << sep << U.front(); sep = ", "; U.pop(); - } - return (out << "}"); -} - - -#define TRACE -#ifdef TRACE - #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) - template - void __f(const char* name, Arg1&& arg1){ - cerr << name << " : " << arg1 << endl; - } - template - void __f(const char* names, Arg1&& arg1, Args&&... args){ - int count_open = 0, len = 1; - for(int k = 1; ; ++k){ - char cur = *(names + k); - count_open += (cur == '(' ? 1 : (cur == ')' ? -1: 0)); - if (cur == ',' && count_open == 0){ - const char* comma = names + k; - cerr.write(names, len) << " : " << arg1 << " | "; - __f(comma + 1, args...); - return; - } - len = (cur == ' ' ? len : k + 1); - } - } -#else - #define trace(...) 1 -#endif - -/*/---------------------------RNG----------------------/*/ -mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); -inline int64_t random_long(long long l = LLONG_MIN,long long r = LLONG_MAX){ - uniform_int_distribution generator(l,r); - return generator(rng); -} -struct custom_hash { // Credits: https://codeforces.com/blog/entry/62393 - static uint64_t splitmix64(uint64_t x) { // http://xorshift.di.unimi.it/splitmix64.c - x += 0x9e3779b97f4a7c15; - x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; - x = (x ^ (x >> 27)) * 0x94d049bb133111eb; - return x ^ (x >> 31); - } - size_t operator()(uint64_t x) const { - static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); - return splitmix64(x + FIXED_RANDOM); - } - template - size_t operator()(pair const& Y) const{ - static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); - return splitmix64(Y.first * 31ull + Y.second + FIXED_RANDOM); - } -}; - -/*/---------------------------Defines----------------------/*/ -#define endl "\n" -#define all(v) (v).begin(),(v).end() -/*/-----------------------------Code begins----------------------------------/*/ - -void solve(){ - int n, m; - cin >> n >> m; - vector matr(n); - - cin >> matr; - - vector> dist(n, vector(m, n + m + 10)); - - - vector> bfs; - - for(int i = 0; i < n; ++i){ - for(int j = 0; j < m; ++j){ - if (matr[i][j] == 'R'){ - bfs.push_back({i, j}); - dist[i][j] = 0; - } - } - } - const vector dx = {-1, 1, 0, 0}; - const vector dy = {0, 0, -1, 1}; - for(int i = 0; i < bfs.size(); ++i){ - auto [x, y] = bfs[i]; - int d = dist[x][y]; - for(int k = 0; k < 4; ++k){ - int nx = x + dx[k], ny = y + dy[k]; - if (nx < 0 || nx >= n || ny < 0 || ny >= m) - continue; - if (dist[nx][ny] > d + 1){ - dist[nx][ny] = d + 1; - bfs.push_back({nx, ny}); - } - } - } - - // trace(dist); - vector> dp(n, vector(m)); - - // dp[0][0] = dist[0][0]; - - for(int i = n - 1; i >= 0; --i){ - for(int j = m - 1; j >= 0; --j){ - if (i == n - 1 && j == m - 1){ - dp[i][j] = dist[i][j]; - continue; - } - int z = (i + j) & 1; - if (i == n - 1){ - dp[i][j] = dp[i][j + 1] + dist[i][j]; - } - else if (j == m - 1){ - dp[i][j] = dp[i + 1][j] + dist[i][j]; - } - else if (z == 0){ - dp[i][j] = max(dp[i + 1][j], dp[i][j + 1]) + dist[i][j]; - } - else{ - dp[i][j] = min(dp[i + 1][j], dp[i][j + 1]) + dist[i][j]; - } - } - } - - // trace(dist[0]); - // trace(dist[1]); - // trace(dist[2]); - - - // trace(dp[0]); - // trace(dp[1]); - // trace(dp[2]); - // trace(dp[1][0], dp[2][1]); - - cout << dp[0][0] << endl; -} - -int main(){ - // Use "set_name".max_load_factor(0.25);"set_name".reserve(512); with unordered set - // Or use gp_hash_table - ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); - cout << fixed << setprecision(25); - cerr << fixed << setprecision(10); - auto start = std::chrono::high_resolution_clock::now(); - - int t = 1; - cin >> t; - while (t--) { - solve(); - } - - auto stop = std::chrono::high_resolution_clock::now(); - auto duration = std::chrono::duration_cast(stop - start); - // cerr << "Time taken : " << ((long double)duration.count())/((long double) 1e9) <<"s "<< endl; -}