| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1344971 | merlin1205 | Tracks in the Snow (BOI13_tracks) | C++17 | 855 ms | 420360 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;
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
