제출 #1344971

#제출 시각아이디문제언어결과실행 시간메모리
1344971merlin1205Tracks in the Snow (BOI13_tracks)C++17
100 / 100
855 ms420360 KiB
#include "bits/stdc++.h"
using namespace std;
#define SorSufi namespace
#define ll long long
#define all(a) a.begin(), a.end()
#define popcount(x) __builtin_popcountll(x)
#define ctz(x) __builtin_ctzll(x)
#define clz(x) __builtin_clzll(x)
#define lsb(x) (x & -x)
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
// #define cerr cout
#define int ll
#define endl '\n'
// #define TIME (1.0 * clock() / CLOCKS_PER_SEC)

bool minimize(int &x, int y) { return x > y ? x = y, 1 : 0; }
bool maximize(int &x, int y) { return x < y ? x = y, 1 : 0; }

SorSufi Fexin{
    vector<pii> d = {{0, 1},{0, -1},{1, 0},{-1, 0}};

    struct Node{int i, j, w;};
    const int N = 4e3;
    int n, m, mx = 0, vs[N + 5][N + 5];
    char a[N + 5][N + 5];

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

    void bfs(){
        deque<Node> q;
        q.push_front({1, 1, 1});
        while(q.size()){
            Node curr = q.front();q.pop_front();
            if(vs[curr.i][curr.j])continue;
            vs[curr.i][curr.j] = 1;
            maximize(mx, curr.w);
            for(pii x : d)if(valid(curr.i +x.first,curr.j + x.second))
                if (a[curr.i][curr.j] != a[curr.i + x.first][curr.j + x.second])
                    q.push_back({curr.i + x.first, curr.j + x.second, curr.w + 1});
                else
                    q.push_front({curr.i + x.first, curr.j + x.second, curr.w});
        }
        cout << mx;
    }

    void Merlin(){
        cin >> n >> m;
        for (int i = 1; i <= n;++i)for (int j = 1; j <= m;++j)cin >> a[i][j];
        bfs();
    }
}

void Merlin() { Fexin::Merlin(); }

signed main(){
    #define FILE_NAME "main"
    ios_base::sync_with_stdio(0);cin.tie(0);

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

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

    // int tc;cin >> tc;while(tc--)
    Merlin();
    // cerr << "TIME PROCCESS: " << TIME;
}

컴파일 시 표준 에러 (stderr) 메시지

tracks.cpp: In function 'int main()':
tracks.cpp:62:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |         freopen(FILE_NAME ".in", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tracks.cpp:63:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |         freopen(FILE_NAME ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tracks.cpp:67:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |         freopen(FILE_NAME ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tracks.cpp:68:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |         freopen(FILE_NAME ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...