Submission #489258

# Submission time Handle Problem Language Result Execution time Memory
489258 2021-11-21T19:39:15 Z cotester Tracks in the Snow (BOI13_tracks) C++14
82.5 / 100
700 ms 181556 KB
#include <iostream>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#include <iterator>
#include <cstring>
#include <fstream>
#include <map>
#include <bitset>
#include <cassert>
#include <stdlib.h>
#include <climits>
#include <stack>
#include <complex> 

using namespace std;

#define fa(a,b)(memset(a,b,sizeof(a)));
#define fill2d(vec,val) for(auto &v:vec)fill(all(v),val)
#define mp(a,b)(make_pair(a,b))
#define pb(a) push_back(a)
#define FORE(i,a,b) for (int i = (a); i <= (b); ++i)
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define ROF(i,a,b) for (int i = (a); i >= (b); --i)
#define FR(i,a) FOR(i,0,a)

#define p (pi())
#define flag (cout<<"here"<<endl)
#define fast ios::sync_with_stdio(0);cin.tie(0)
#define sz(x) ((int)(x.size()))
#define f first
#define s second
#define all(x) begin(x), end(x)
#define in(r,R) (r>=0&&r<=R)

using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vector<int> >;
using pii = pair<int, int>;
using pdd = pair<double, double>;

const int dx[8] = {1,0,-1,0,1,1,-1,-1}; //first 4 are normal
const int dy[8] = {0,1,0,-1,1,-1,1,-1};
const int MOD = 1000000007;
const ll NMOD = 1000000009;

const int AR_MAX = (1 << 7) - 1; //when using memeset
const int AR_MAX_VAL = 2139062143;
//^ Not recommended unless 
//  there's no other way do to what you need to do
const double PI  =3.141592653589793238463;
const double EPS = 10e-9;

void _forAllUnusedConsts() { 
//to silence unused variable warnings
	cout << 
	AR_MAX << 
	AR_MAX_VAL<<
	dx[0]<<
	dy[1]<<
	PI<<
	EPS<<
	endl;
}
template<class Q>
typename Q::value_type pop(Q& q) {
    auto result = q.front();
    q.pop();
    return result;
};

//reading input the "java" way 
//(aka with method calls)
int pi() {
	int N;
	cin >> N;
	return N;
}
ll pl() {
	ll N;
	cin >> N;
	return N;
}
char pc() {
	char c;
	cin >> c;
	return c;
}
string ps() {
	string s;
	cin >> s;
	return s;
}


//other
template<class T1, class T2>
ll powf(T1 a, T2 b) {
	if(b<0)return 0;
	if (b == 0)return 1;
	ll val = powf(a, (ll)(b / 2));
	if (b & 1) {

		return ((val * val) % MOD * a) % MOD;
	} else {
		return (val * val) % MOD;
	}
}
string bin(int n, int digits) {
	string s = bitset<32>(n).to_string();
	s.erase(0, s.length() - digits);
	return s;
}
void IO(string fileName) {
	freopen((fileName + ".in").c_str(), "r", stdin);
	freopen((fileName + ".out").c_str(), "w", stdout);
}
ll cp(complex<ll> a, complex<ll> b){
	return (conj(a)*b).imag();
}
bool eq(double a, double b){
	return fabs(a-b)<=EPS;
}

/*

5 8
FFR.....
.FRRR...
.FFFFF..
..RRRFFR
.....FFF
 */
int main() {
	fast;
	int R = p;
	int C = p;
	char g[R][C];
	int dist[R][C]; fa(dist,0);
	dist[0][0] = 1;
	FR(r,R){
		FR(c,C){
			char cur = pc();
			g[r][c] = cur;
		}
	}
	deque<pii> q;
	q.push_back({0,0});
	int ans = 1;
	while(sz(q)){
		pii cur = q.front(); q.pop_front();
		FR(i,4){
			int r2 = cur.f+dx[i];
			int c2 = cur.s+dy[i];
			if(in(r2,R)&&in(c2,C)&&g[r2][c2]!='.'&&!dist[r2][c2]){

				if(g[r2][c2]==g[cur.f][cur.s]){
					dist[r2][c2] = dist[cur.f][cur.s];
					q.push_front({r2,c2});
				}else{
					dist[r2][c2] = dist[cur.f][cur.s]+1;
					q.push_back({r2,c2});

				}
				ans = max(ans,dist[r2][c2]);
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Compilation message

tracks.cpp: In function 'void IO(std::string)':
tracks.cpp:118:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  118 |  freopen((fileName + ".in").c_str(), "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tracks.cpp:119:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  119 |  freopen((fileName + ".out").c_str(), "w", stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 11 ms 1724 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 7 ms 1356 KB Output is correct
5 Correct 2 ms 716 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 3 ms 588 KB Output is correct
11 Correct 2 ms 588 KB Output is correct
12 Correct 5 ms 844 KB Output is correct
13 Correct 3 ms 716 KB Output is correct
14 Correct 3 ms 716 KB Output is correct
15 Correct 11 ms 1740 KB Output is correct
16 Correct 12 ms 1784 KB Output is correct
17 Correct 8 ms 1724 KB Output is correct
18 Correct 6 ms 1356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 580 KB Output is correct
2 Correct 46 ms 9444 KB Output is correct
3 Runtime error 318 ms 163372 KB Execution killed with signal 11
4 Correct 88 ms 21268 KB Output is correct
5 Runtime error 172 ms 93072 KB Execution killed with signal 11
6 Runtime error 359 ms 172244 KB Execution killed with signal 11
7 Incorrect 1 ms 460 KB Output isn't correct
8 Correct 1 ms 588 KB Output is correct
9 Correct 2 ms 588 KB Output is correct
10 Runtime error 2 ms 708 KB Execution killed with signal 11
11 Correct 1 ms 588 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 47 ms 9208 KB Output is correct
14 Correct 28 ms 5580 KB Output is correct
15 Correct 23 ms 6072 KB Output is correct
16 Correct 24 ms 4044 KB Output is correct
17 Correct 134 ms 22384 KB Output is correct
18 Correct 108 ms 22028 KB Output is correct
19 Correct 108 ms 20780 KB Output is correct
20 Correct 79 ms 19288 KB Output is correct
21 Correct 202 ms 49048 KB Output is correct
22 Runtime error 179 ms 92988 KB Execution killed with signal 11
23 Correct 251 ms 41384 KB Output is correct
24 Incorrect 139 ms 47968 KB Output isn't correct
25 Correct 506 ms 81876 KB Output is correct
26 Correct 440 ms 113708 KB Output is correct
27 Correct 595 ms 115168 KB Output is correct
28 Correct 700 ms 94728 KB Output is correct
29 Runtime error 373 ms 181556 KB Execution killed with signal 11
30 Correct 648 ms 98156 KB Output is correct
31 Correct 498 ms 52956 KB Output is correct
32 Correct 559 ms 104948 KB Output is correct