답안 #989726

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
989726 2024-05-28T16:20:01 Z Ralph_J Tracks in the Snow (BOI13_tracks) C++17
0 / 100
2000 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;}


void solve(){
    int n, m; cin >> n >> m;
    vector<string> a(n); cin >> a;

    vector<vector<int>> color(n, vector<int>(m, 0)); 
    int cur_color = 1;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            if(a[i][j] == '.') continue;
            if(color[i][j] == 0) {
                color[i][j] = cur_color;
                cur_color++; 
            }
            if(i < n - 1){
                if(a[i + 1][j] == a[i][j]) color[i + 1][j] = color[i][j];
            }
            if(j < m - 1){
                if(a[i][j + 1] == a[i][j]) color[i][j + 1] = color[i][j];
            }
        }
    }
    for(auto e : color) cout << e << '\n';
    vector<set<int>> adj(cur_color);
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(a[i][j] == '.') continue;
            if(i < n - 1 && a[i][j] != a[i + 1][j]){
                adj[color[i][j]].insert(color[i + 1][j]);
                adj[color[i + 1][j]].insert(color[i][j]);
            }
            if(j < m - 1 && a[i][j] != a[i][j + 1]){
                adj[color[i][j]].insert(color[i][j + 1]);
                adj[color[i][j + 1]].insert(color[i][j]);
            }
        }   
    }
    queue<pair<int,int>> Q; Q.push({1, 0});
    vector<int> vis(cur_color); vis[1] = 1;
    int res = 0;
    while(!Q.empty()){
        int root = Q.front().first;
        int d = Q.front().second;
        res = max(res, d);
        Q.pop();
        for(auto e : adj[root]){
            if(vis[e]) continue;
            vis[e] = 1;
            Q.push({e, d + 1});
        }
    }
    cout << res + 1 << '\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;}
      |                                                            ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 48 ms 18768 KB Output isn't correct
2 Incorrect 1 ms 344 KB Output isn't correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Runtime error 15 ms 6984 KB Execution killed with signal 11
5 Incorrect 9 ms 3676 KB Output isn't correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Incorrect 1 ms 348 KB Output isn't correct
8 Incorrect 1 ms 604 KB Output isn't correct
9 Incorrect 1 ms 604 KB Output isn't correct
10 Incorrect 9 ms 3672 KB Output isn't correct
11 Incorrect 3 ms 1372 KB Output isn't correct
12 Incorrect 15 ms 6740 KB Output isn't correct
13 Incorrect 9 ms 3676 KB Output isn't correct
14 Incorrect 9 ms 3676 KB Output isn't correct
15 Incorrect 39 ms 16868 KB Output isn't correct
16 Incorrect 45 ms 18772 KB Output isn't correct
17 Incorrect 35 ms 14420 KB Output isn't correct
18 Runtime error 15 ms 7000 KB Execution killed with signal 11
# 결과 실행 시간 메모리 Grader output
1 Runtime error 83 ms 4432 KB Execution killed with signal 11
2 Incorrect 215 ms 81492 KB Output isn't correct
3 Incorrect 1684 ms 616592 KB Output isn't correct
4 Incorrect 381 ms 116180 KB Output isn't correct
5 Runtime error 1571 ms 1048576 KB Execution killed with signal 9
6 Incorrect 1511 ms 464732 KB Output isn't correct
7 Runtime error 82 ms 4180 KB Execution killed with signal 11
8 Runtime error 91 ms 4508 KB Execution killed with signal 11
9 Incorrect 4 ms 1624 KB Output isn't correct
10 Incorrect 2 ms 860 KB Output isn't correct
11 Runtime error 49 ms 3036 KB Execution killed with signal 11
12 Incorrect 5 ms 3420 KB Output isn't correct
13 Incorrect 228 ms 81392 KB Output isn't correct
14 Incorrect 124 ms 46676 KB Output isn't correct
15 Incorrect 137 ms 50472 KB Output isn't correct
16 Incorrect 48 ms 19920 KB Output isn't correct
17 Incorrect 545 ms 210512 KB Output isn't correct
18 Incorrect 560 ms 196064 KB Output isn't correct
19 Incorrect 374 ms 116316 KB Output isn't correct
20 Incorrect 367 ms 136276 KB Output isn't correct
21 Runtime error 987 ms 657936 KB Execution killed with signal 11
22 Execution timed out 3760 ms 1048576 KB Time limit exceeded
23 Incorrect 1018 ms 382176 KB Output isn't correct
24 Runtime error 1246 ms 920688 KB Execution killed with signal 11
25 Execution timed out 2081 ms 806716 KB Time limit exceeded
26 Incorrect 619 ms 146620 KB Output isn't correct
27 Incorrect 887 ms 246168 KB Output isn't correct
28 Incorrect 1493 ms 464516 KB Output isn't correct
29 Incorrect 1336 ms 396624 KB Output isn't correct
30 Incorrect 1177 ms 348564 KB Output isn't correct
31 Execution timed out 2029 ms 791888 KB Time limit exceeded
32 Incorrect 925 ms 281392 KB Output isn't correct