Submission #874195

# Submission time Handle Problem Language Result Execution time Memory
874195 2023-11-16T12:28:43 Z Ralph_J Tracks in the Snow (BOI13_tracks) C++17
45.3125 / 100
2000 ms 100188 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(v) sort(all(v))
#define REVERSE(v) reverse(all(v))
#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;}
vector<ll>primeFactors(ll num){vector<ll>prime;for(ll 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;}
ll power(ll x, ll y, ll mod = 1e9+7){ll res = 1; x %= mod; while(y > 0){if(y & 1) res = (res * x) % mod; y >>= 1; x = (x * x) % mod;} return res;}
vector<ll> divisors(ll n){ vector<ll> div; for(ll 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 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;}

void solve(){
    int n, m; cin >> n >> m;
    vector<vector<char>> a(n, vector<char>(m)); cin >> a;
    map<char, int> cnt;
    for(int i = 0; i < n; i++){
        for(int j = 0;  j < m; j++){
            cnt[a[i][j]]++;
        }
    }
    int res = 0;
    while(cnt['R'] != 0 && cnt['F'] != 0){
        vector<vector<bool>> vis(n, vector<bool>(m, 0));
        stack<pair<int,int>> st;
        st.push({0, 0}); 
        while(!st.empty()){
            int i = st.top().first, j = st.top().second;
            st.pop();

            int dx[] = {-1, 1, 0, 0};
            int dy[] = {0, 0, 1, -1};
            for(int t = 0; t < 4; t++){
                int inew = i + dx[t], jnew = j + dy[t];
                if(inew < 0 || inew >= n || jnew < 0 || jnew >= m || vis[inew][jnew] || a[i][j] != a[inew][jnew]) continue;
                st.push({inew, jnew}); vis[inew][jnew] = 1;
            }
        }
        for(int i = 0; i < n; i++){
            for(int j = 0; j < m; j++){
                if(vis[i][j]){
                    cnt[a[i][j]]--;
                    a[i][j] = (a[i][j] == 'R' ? 'F' : 'R');
                    cnt[a[i][j]]++;
                }
            }
        }
        res++;
        // for(auto e : a){
        //     cout << e << '\n';
        // }cout << '\n';
    }
    cout << res + 1 << '\n';
}


int main()
{
    // freopen("input.txt","r",stdin);
    // freopen("tractor.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 'int decimal(std::vector<long long int>)':
tracks.cpp:45:62: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 | 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 Correct 181 ms 1996 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 15 ms 1264 KB Output is correct
5 Correct 66 ms 656 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 3 ms 348 KB Output is correct
10 Correct 74 ms 636 KB Output is correct
11 Correct 3 ms 604 KB Output is correct
12 Correct 53 ms 904 KB Output is correct
13 Correct 65 ms 652 KB Output is correct
14 Correct 65 ms 656 KB Output is correct
15 Correct 450 ms 1716 KB Output is correct
16 Correct 174 ms 1704 KB Output is correct
17 Correct 440 ms 1156 KB Output is correct
18 Correct 15 ms 1344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2065 ms 964 KB Time limit exceeded
2 Execution timed out 2041 ms 5016 KB Time limit exceeded
3 Execution timed out 2017 ms 34020 KB Time limit exceeded
4 Execution timed out 2003 ms 8792 KB Time limit exceeded
5 Execution timed out 2036 ms 19312 KB Time limit exceeded
6 Execution timed out 2025 ms 99356 KB Time limit exceeded
7 Correct 1856 ms 980 KB Output is correct
8 Execution timed out 2041 ms 964 KB Time limit exceeded
9 Correct 148 ms 648 KB Output is correct
10 Correct 459 ms 496 KB Output is correct
11 Correct 773 ms 992 KB Output is correct
12 Correct 1580 ms 496 KB Output is correct
13 Execution timed out 2033 ms 5044 KB Time limit exceeded
14 Execution timed out 2044 ms 3320 KB Time limit exceeded
15 Execution timed out 2056 ms 2396 KB Time limit exceeded
16 Execution timed out 2029 ms 2596 KB Time limit exceeded
17 Execution timed out 2051 ms 10776 KB Time limit exceeded
18 Execution timed out 2079 ms 8896 KB Time limit exceeded
19 Execution timed out 2052 ms 8696 KB Time limit exceeded
20 Execution timed out 2090 ms 7740 KB Time limit exceeded
21 Execution timed out 2024 ms 20052 KB Time limit exceeded
22 Execution timed out 2041 ms 19540 KB Time limit exceeded
23 Execution timed out 2051 ms 18284 KB Time limit exceeded
24 Execution timed out 2094 ms 19416 KB Time limit exceeded
25 Execution timed out 2009 ms 33992 KB Time limit exceeded
26 Correct 133 ms 24328 KB Output is correct
27 Correct 1569 ms 99724 KB Output is correct
28 Execution timed out 2032 ms 99372 KB Time limit exceeded
29 Execution timed out 2043 ms 100188 KB Time limit exceeded
30 Execution timed out 2045 ms 97540 KB Time limit exceeded
31 Execution timed out 2040 ms 32348 KB Time limit exceeded
32 Execution timed out 2093 ms 68620 KB Time limit exceeded