Submission #881257

# Submission time Handle Problem Language Result Execution time Memory
881257 2023-12-01T02:00:12 Z JustA Tracks in the Snow (BOI13_tracks) C++17
100 / 100
541 ms 133988 KB
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);
#define ll long long
#define pb push_back
#define pf push_front
#define db double
#define X first
#define Y second
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define nl '\n'
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<pair<int,int>>
#define dbgArr(a,index) for(int i=0;i<(index);i++) cerr << a[i] << ' ';
#define dbgMat(a,n,m) for(int i=0;i<(n);i++) {for(int j=0;j<(m);j++) cerr << a[i][j] << ' '; cerr << nl;}
#define dbg(x) cerr << (x) << ' ';
#define donetest cout << "done\n";


const int M = 1e9+7;
const int N = 4e3+5;
const ll inf = 1e18;
const ll INF = 0x3f;

int moveX[] = {0, 0, 1, -1};
int moveY[] = {1, -1, 0, 0};
char moveC[] = {'R', 'L', 'D', 'U'};

void indef(){
	#define JA "input"
	if(fopen(JA ".inp", "r")){
		freopen(JA ".inp","r",stdin);
		freopen(JA ".out","w",stdout);	
	}
}

char snow[N][N];
int dist[N][N];
int h,w;
int ans = 0;
bool check(int x,int y){
	return 0 <= x && x < h && 0 <= y && y < w && snow[x][y] != '.';
}
void bfs01(){
	deque<ii> dq;
	dq.pb({0, 0});
	dist[0][0] = 1;
	while(!dq.empty()){
		auto [x, y] = dq.front();dq.pop_front();
		ans = max(ans, dist[x][y]);
		for(int i=0;i<4;i++){
			int dx = x + moveX[i];
			int dy = y + moveY[i];
			if(check(dx,dy) && !dist[dx][dy]){
				if(snow[dx][dy] == snow[x][y]){
					dist[dx][dy] = dist[x][y];
					dq.push_front({dx, dy});
				}
				else{
					dist[dx][dy] = dist[x][y] + 1;
					dq.pb({dx, dy});
				}
			}
		}
	}
}
void solve(){
	cin >> h >> w;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin >> snow[i][j];
		}
	}

	bfs01();
	cout << ans;
}
int main(){
	fast;
	indef();
	int tt=1;
	// cin >> tt;
	while(tt--) solve();
}

Compilation message

tracks.cpp: In function 'void indef()':
tracks.cpp:34:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |   freopen(JA ".inp","r",stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
tracks.cpp:35:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |   freopen(JA ".out","w",stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 11 ms 7524 KB Output is correct
2 Correct 1 ms 2516 KB Output is correct
3 Correct 1 ms 2528 KB Output is correct
4 Correct 7 ms 7528 KB Output is correct
5 Correct 3 ms 5992 KB Output is correct
6 Correct 1 ms 2408 KB Output is correct
7 Correct 1 ms 2664 KB Output is correct
8 Correct 1 ms 2664 KB Output is correct
9 Correct 1 ms 2920 KB Output is correct
10 Correct 2 ms 3688 KB Output is correct
11 Correct 2 ms 3432 KB Output is correct
12 Correct 4 ms 6032 KB Output is correct
13 Correct 3 ms 5992 KB Output is correct
14 Correct 3 ms 5940 KB Output is correct
15 Correct 9 ms 7528 KB Output is correct
16 Correct 10 ms 7752 KB Output is correct
17 Correct 9 ms 7460 KB Output is correct
18 Correct 7 ms 7524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 32356 KB Output is correct
2 Correct 38 ms 16484 KB Output is correct
3 Correct 246 ms 73792 KB Output is correct
4 Correct 68 ms 35612 KB Output is correct
5 Correct 165 ms 55960 KB Output is correct
6 Correct 541 ms 107828 KB Output is correct
7 Correct 9 ms 33112 KB Output is correct
8 Correct 9 ms 32344 KB Output is correct
9 Correct 3 ms 2652 KB Output is correct
10 Correct 1 ms 2528 KB Output is correct
11 Correct 9 ms 32604 KB Output is correct
12 Correct 1 ms 3164 KB Output is correct
13 Correct 38 ms 16320 KB Output is correct
14 Correct 24 ms 13140 KB Output is correct
15 Correct 20 ms 15428 KB Output is correct
16 Correct 18 ms 8284 KB Output is correct
17 Correct 95 ms 31172 KB Output is correct
18 Correct 77 ms 38076 KB Output is correct
19 Correct 67 ms 35516 KB Output is correct
20 Correct 58 ms 27056 KB Output is correct
21 Correct 146 ms 54868 KB Output is correct
22 Correct 164 ms 55888 KB Output is correct
23 Correct 187 ms 46588 KB Output is correct
24 Correct 143 ms 52032 KB Output is correct
25 Correct 395 ms 94288 KB Output is correct
26 Correct 458 ms 133988 KB Output is correct
27 Correct 449 ms 112668 KB Output is correct
28 Correct 511 ms 107732 KB Output is correct
29 Correct 516 ms 105456 KB Output is correct
30 Correct 506 ms 111020 KB Output is correct
31 Correct 371 ms 75184 KB Output is correct
32 Correct 487 ms 110644 KB Output is correct