Submission #989864

# Submission time Handle Problem Language Result Execution time Memory
989864 2024-05-28T22:10:28 Z Ralph_J Tracks in the Snow (BOI13_tracks) C++17
0 / 100
1773 ms 1048576 KB
// #pragma GCC optimize("Ofast, unroll-loops, no-stack-protector, fast-math, O3, omit-frame-pointer, inline, avx, avx2, fma")
#include <bits/stdc++.h>
using namespace std;
#define SZ(x) ((int)(x).size()) // size of a container
#define F(i, n) for (int i = 0; i < (int)(n); i++) 
#define ALL(a, x) memset(a, x, sizeof(a)) // set elements of array to some value
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define REMAX(a, b) (a) = max((a), (b)) // set a to the maximum of a and b
#define REMIN(a, b) (a) = min((a), (b));
#define FOREACH(i, t) for (typeof(t.begin()) i = t.begin(); i != t.end(); i++) // traverse an STL data structure
#define all(c) (c).begin(), (c).end() // handy for function like "sort()"
#define contain(c, x) ((c).find(x) != (c).end())
#define present(c, x) (count(all(c), x)>0)
typedef long long ll; // data types used often, but you don't want to type them time by time
typedef unsigned long long ull;
const long double PI = 3.1415926535897932384626;
const int mod = 1000000007;
#define dbg(var) cerr << #var << " = " << (var) << endl; // for debug
#define pb push_back // for vectors
#define SORT(p) sort(all(p))
#define REVERSE(p) reverse(all(p))
#define onecount __builtin_popcount // count number of 1's in a number
#define highbit(x) (63 - __builtin_clzll(x)) // get the index of the highest bit set
#define lowbit(x) __builtin_ctzll(x) // get the index of the lowest bit set
#define bitcount(x) (__builtin_popcount(x) + __builtin_popcount(x >> 32)) // count number of 1's in a number in O(1) time
#define mid(l, r) ((l) + (((r) - (l)) >> 1))
typedef int elem_t;
template <typename T, typename TT>
ostream &operator<<(ostream &s, pair<T, TT> t) { return s << "(" << t.first << "," << t.second << ")"; }
template <typename T>
ostream &operator<<(ostream &s, vector<T> t){ F(i, SZ(t)) s << t[i] << " ";return s;}
template <typename T>
istream &operator>>(istream &in, vector<T>&e){for(auto&x : e) cin >> x; return in;}
template <typename T, typename TT>
istream &operator>>(istream &in, vector<pair<T, TT>>&e){for(auto&x : e) cin >> x.first >> x.second; return in;} 
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll largest_multiple_smaller_than_x(ll a, ll k){ return (k / a) * a;}
ll smallest_multiple_greater_than_x(ll a, ll k){ return ((k + a - 1) / a) * a;}
vector<ll>sieve(ll num){vector<ll>prime;vector<bool>isPrime(num + 1, true);isPrime[0] = isPrime[1] = false;for(int i = 2; i <= num; i++){if(isPrime[i]){prime.push_back(i);for(int j = i * 2; j <= num; j += i) isPrime[j] = false;}}return prime;}
#define int long long
vector<int>primeFactors(int num){vector<int>prime;for(int i = 2; i * i <= num; i++){while(num % i == 0){prime.push_back(i);num /= i;}}{if(num > 1) prime.push_back(num);}return prime;}
bool is_prime(ll num){if(num < 2) return false;for(ll i = 2; i * i <= num; i++){if(num % i == 0) return false;}return true;}
vector<int>binary(ll num){vector<int>binary;while(num){binary.push_back(num % 2); num >>= 1;} reverse(all(binary)); return binary;}
int decimal(vector<ll>binary){ int num = 0; for(int i = 0; i < binary.size(); i++){num += binary[i] * (1 << i);}return num;}
ll factorial(ll num, ll mod = 1e9+7){ ll fact = 1; for(ll i = 1; i <= num; i++) fact = (fact * i) % mod; return fact;}
vector<int> divisors(int n){ vector<int> div; for(int i = 1; i * i <= n; i++){ if(n % i == 0){ div.push_back(i); if(i * i != n) div.push_back(n / i); } } return div; }
ll power(ll x, ll y, ll mod = 1e18+7){ll res = 1; x %= mod; while(y > 0){if(y & 1) res = (res * x) % mod; y >>= 1; x = (x * x) % mod;} return res;}
ll mod_inverse(ll num, ll mod = 1e9+7){ return power(num, mod - 2, mod);}
ll NchooseK(ll n, ll k, ll mod = 1e9+7){ll res = 1; k = min(k, n - k); for(ll i = 0; i < k; i++){ res = (res * (n - i)) % mod; res = (res * mod_inverse(i + 1, mod)) % mod;} return res;}

int n, m;
string a[100000]; 
int dx[4]{1, -1, 0, 0}, dy[4]{0, 0, 1, -1};

bool inside(int i, int j){
    return (i >= 0 && j >= 0 && i < n && j < m && a[i][j] != '.');
}

void solve(){
    cin >> n >> m;
    for(int i = 0; i < n; i++) cin >> a[i];

    deque<pair<int,int>> Q;
    Q.push_back({0, 0});
    vector<vector<int>> dist(n, vector<int>(m, 0));
    int res = 0;
    while(!Q.empty()){
        int i = Q.front().first, j = Q.front().second;
        res = max(res, dist[i][j]);
        Q.pop_front();
        for(int x = 0; x < 4; x++){
            int i2 = i + dx[x], j2 = j + dy[x];
            if(inside(i2, j2) && dist[i2][j2] == 0){
                if(a[i][j] == a[i2][j2]){
                    dist[i2][j2] = dist[i][j];
                    Q.push_front({i2, j2});
                }
                else{
                    dist[i2][j2] = dist[i][j] + 1;
                    Q.push_back({i2, j2});
                }
            }
        }
    }
    cout << res << '\n';
}

int32_t main()
{
    // freopen(".in","r",stdin);
    // freopen(".out","w",stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int TT = 1;
    // cin >> TT;
    while(TT--){
        solve();
    }
    return 0; 
}

Compilation message

tracks.cpp: In function 'long long int decimal(std::vector<long long int>)':
tracks.cpp:46:62: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 | int decimal(vector<ll>binary){ int num = 0; for(int i = 0; i < binary.size(); i++){num += binary[i] * (1 << i);}return num;}
      |                                                            ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 1018 ms 1048576 KB Execution killed with signal 9
2 Runtime error 1534 ms 1048576 KB Execution killed with signal 9
3 Runtime error 1054 ms 1048576 KB Execution killed with signal 9
4 Runtime error 983 ms 1048576 KB Execution killed with signal 9
5 Runtime error 1574 ms 1048576 KB Execution killed with signal 9
6 Runtime error 1773 ms 1048576 KB Execution killed with signal 9
7 Runtime error 1042 ms 1048576 KB Execution killed with signal 9
8 Runtime error 892 ms 1048576 KB Execution killed with signal 9
9 Runtime error 998 ms 1048576 KB Execution killed with signal 9
10 Runtime error 1532 ms 1048576 KB Execution killed with signal 9
11 Runtime error 1521 ms 1048576 KB Execution killed with signal 9
12 Runtime error 906 ms 1048576 KB Execution killed with signal 9
13 Runtime error 1573 ms 1048576 KB Execution killed with signal 9
14 Runtime error 1558 ms 1048576 KB Execution killed with signal 9
15 Runtime error 985 ms 1048576 KB Execution killed with signal 9
16 Runtime error 1000 ms 1048576 KB Execution killed with signal 9
17 Runtime error 1524 ms 1048576 KB Execution killed with signal 9
18 Runtime error 847 ms 1048576 KB Execution killed with signal 9
# Verdict Execution time Memory Grader output
1 Runtime error 1498 ms 1048576 KB Execution killed with signal 9
2 Runtime error 1539 ms 1048576 KB Execution killed with signal 9
3 Runtime error 1417 ms 1048576 KB Execution killed with signal 9
4 Runtime error 1220 ms 1048576 KB Execution killed with signal 9
5 Runtime error 1355 ms 1048576 KB Execution killed with signal 9
6 Runtime error 1434 ms 1048576 KB Execution killed with signal 9
7 Runtime error 1517 ms 1048576 KB Execution killed with signal 9
8 Runtime error 1448 ms 1048576 KB Execution killed with signal 9
9 Runtime error 1465 ms 1048576 KB Execution killed with signal 9
10 Runtime error 1540 ms 1048576 KB Execution killed with signal 9
11 Runtime error 1518 ms 1048576 KB Execution killed with signal 9
12 Runtime error 1578 ms 1048576 KB Execution killed with signal 9
13 Runtime error 1547 ms 1048576 KB Execution killed with signal 9
14 Runtime error 1522 ms 1048576 KB Execution killed with signal 9
15 Runtime error 1512 ms 1048576 KB Execution killed with signal 9
16 Runtime error 976 ms 1048576 KB Execution killed with signal 9
17 Runtime error 1499 ms 1048576 KB Execution killed with signal 9
18 Runtime error 1433 ms 1048576 KB Execution killed with signal 9
19 Runtime error 921 ms 1048576 KB Execution killed with signal 9
20 Runtime error 1459 ms 1048576 KB Execution killed with signal 9
21 Runtime error 1363 ms 1048576 KB Execution killed with signal 9
22 Runtime error 1362 ms 1048576 KB Execution killed with signal 9
23 Runtime error 1049 ms 1048576 KB Execution killed with signal 9
24 Runtime error 1435 ms 1048576 KB Execution killed with signal 9
25 Runtime error 1373 ms 1048576 KB Execution killed with signal 9
26 Runtime error 811 ms 1048576 KB Execution killed with signal 9
27 Runtime error 766 ms 1048576 KB Execution killed with signal 9
28 Runtime error 1433 ms 1048576 KB Execution killed with signal 9
29 Runtime error 840 ms 1048576 KB Execution killed with signal 9
30 Runtime error 796 ms 1048576 KB Execution killed with signal 9
31 Runtime error 937 ms 1048576 KB Execution killed with signal 9
32 Runtime error 1514 ms 1048576 KB Execution killed with signal 9