# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
417566 |
2021-06-04T00:50:31 Z |
nkato |
Mecho (IOI09_mecho) |
C++17 |
|
202 ms |
7020 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using db = double;
using str = string; // yay python!
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using pd = pair<db,db>;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector<str>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;
#define tcT template<class T
#define tcTU tcT, class U
// ^ lol this makes everything look weird but I'll try it
tcT> using V = vector<T>;
tcT, size_t SZ> using AR = array<T,SZ>;
tcT> using PR = pair<T,T>;
// pairs
#define mp make_pair
#define fi first
#define se second
// vectors
// oops size(x), rbegin(x), rend(x) need C++17
#define sz(x) int((x).size())
#define all(x) bg(x), end(x)
#define rall(x) x.rbegin(), x.rend()
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pb push_back
#define eb emplace_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
tcT> int lwb(V<T>& a, const T& b) { return int(lb(all(a),b)-bg(a)); }
// loops
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)
const int MOD = 1e9+7; // 998244353;
const int MX = 2e5+5;
const ll INF = 1e18; // not too close to LLONG_MAX
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1}; // for every grid problem!!
template<class T> using pqg = priority_queue<T,vector<T>,greater<T>>;
tcT> bool ckmin(T& a, const T& b) {
return b < a ? a = b, 1 : 0; } // set a = min(a,b)
tcT> bool ckmax(T& a, const T& b) {
return a < b ? a = b, 1 : 0; }
#define tcTUU tcT, class ...U
// TO_STRING
#define ts to_string
str ts(char c) { return str(1,c); }
str ts(const char* s) { return (str)s; }
str ts(str s) { return s; }
str ts(bool b) {
#ifdef LOCAL
return b ? "true" : "false";
#else
return ts((int)b);
#endif
}
tcTU> str ts(pair<T,U> p);
tcT> str ts(T v) { // containers with begin(), end()
#ifdef LOCAL
bool fst = 1; str res = "{";
for (const auto& x: v) {
if (!fst) res += ", ";
fst = 0; res += ts(x);
}
res += "}"; return res;
#else
bool fst = 1; str res = "";
for (const auto& x: v) {
if (!fst) res += " ";
fst = 0; res += ts(x);
}
return res;
#endif
}
tcTU> str ts(pair<T,U> p) {
#ifdef LOCAL
return "("+ts(p.fi)+", "+ts(p.se)+")";
#else
return ts(p.fi)+" "+ts(p.se);
#endif
}
// OUTPUT
tcT> void pr(T x) { cout << ts(x); }
tcTUU> void pr(const T& t, const U&... u) {
pr(t); pr(u...); }
void ps() { pr("\n"); } // print w/ spaces
tcTUU> void ps(const T& t, const U&... u) {
pr(t); if (sizeof...(u)) pr(" "); ps(u...); }
// DEBUG
void DBG() { cerr << "]" << endl; }
tcTUU> void DBG(const T& t, const U&... u) {
cerr << ts(t); if (sizeof...(u)) cerr << ", ";
DBG(u...); }
#ifdef LOCAL // compile with -DLOCAL, chk -> fake assert
#define dbg(...) cerr << "Line(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#define chk(...) if (!(__VA_ARGS__)) cerr << "Line(" << __LINE__ << ") -> function(" \
<< __FUNCTION__ << ") -> CHK FAILED: (" << #__VA_ARGS__ << ")" << "\n", exit(0);
#else
#define dbg(...) 0
#define chk(...) 0
#endif
void setPrec() { cout << fixed << setprecision(15); }
void unsyncIO() { cin.tie(0)->sync_with_stdio(0); }
// FILE I/O
void setIn(str s) { freopen(s.c_str(),"r",stdin); }
void setOut(str s) { freopen(s.c_str(),"w",stdout); }
void setIO(str s = "") {
unsyncIO(); setPrec();
// cin.exceptions(cin.failbit);
// throws exception when do smth illegal
// ex. try to read letter into int
if (sz(s)) setIn(s+".in"), setOut(s+".out"); // for USACO
}
const int nax = 805;
str f[nax]; // [state #][row][col]
int dst[nax][nax][2]; // [row][col][0 for mecho, 1 for bee]
int n, s;
pi m; // mecho starting pos
void reset() {
F0R(i, nax) {
F0R(j, nax) {
dst[i][j][0] = -1;
}
}
}
bool check(int x, int y) {
if (x < 0 || x >= n || y < 0 || y >= n) return 0;
if (f[y][x] == 'T') return 0;
return 1;
}
bool tri(int t) {
queue<pi> q;
dst[m.se][m.fi][0] = t;
q.push(m);
while(!q.empty()) {
pi u = q.ft;
dbg(u, dst[u.se][u.fi][0]);
if (f[u.se][u.fi] == 'D') {
return true;
}
q.pop();
F0R(i, 4) {
pi v = mp(u.fi+dx[i], u.se+dy[i]);
dbg(v);
if (check(v.fi, v.se) && dst[v.se][v.fi][0] == -1) {
dst[v.se][v.fi][0] = dst[u.se][u.fi][0]+1;
dbg(dst[v.se][v.fi][1]*s, dst[v.se][v.fi][0]);
if ((dst[v.se][v.fi][1]*s) >= dst[v.se][v.fi][0]) {
q.push(v);
}
}
}
}
return false;
}
void bfs(vpi h) {
queue<pi> q;
trav(x, h) {
q.push(x);
dst[x.se][x.fi][1] = 0;
}
while(!q.empty()) {
pi u = q.ft;
q.pop();
F0R(i, 4) {
pi v = mp(u.fi+dx[i], u.se+dy[i]);
if (check(v.fi, v.se) && dst[v.se][v.fi][1] == -1) {
dst[v.se][v.fi][1] = dst[u.se][u.fi][1]+1;
q.push(v);
}
}
}
}
int main() {
setIO();
F0R(i, nax) F0R(j, nax) F0R(k, 2) dst[i][j][k] = -1;
cin >> n >> s;
F0R(i, n) cin >> f[i];
vpi h;
F0R(i, n) {
F0R(j, n) {
if (f[i][j] == 'H') h.pb(mp(j, i));
if (f[i][j] == 'M') m = {j, i};
}
}
// BEE BFS
bfs(h);
// BEAR BINARY SEARCH
int lo = -1, hi = n*n+1;
while(lo < hi) {
dbg(lo, hi);
int mid = (lo+hi+1)/2;
reset();
if (tri(mid*s)) lo = mid;
else hi = mid-1;
}
ps(lo);
}
Compilation message
mecho.cpp: In function 'bool tri(int)':
mecho.cpp:127:19: warning: statement has no effect [-Wunused-value]
127 | #define dbg(...) 0
| ^
mecho.cpp:171:3: note: in expansion of macro 'dbg'
171 | dbg(u, dst[u.se][u.fi][0]);
| ^~~
mecho.cpp:127:19: warning: statement has no effect [-Wunused-value]
127 | #define dbg(...) 0
| ^
mecho.cpp:178:4: note: in expansion of macro 'dbg'
178 | dbg(v);
| ^~~
mecho.cpp:127:19: warning: statement has no effect [-Wunused-value]
127 | #define dbg(...) 0
| ^
mecho.cpp:181:5: note: in expansion of macro 'dbg'
181 | dbg(dst[v.se][v.fi][1]*s, dst[v.se][v.fi][0]);
| ^~~
mecho.cpp: In function 'int main()':
mecho.cpp:127:19: warning: statement has no effect [-Wunused-value]
127 | #define dbg(...) 0
| ^
mecho.cpp:232:3: note: in expansion of macro 'dbg'
232 | dbg(lo, hi);
| ^~~
mecho.cpp: In function 'void setIn(str)':
mecho.cpp:134:28: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
134 | void setIn(str s) { freopen(s.c_str(),"r",stdin); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
mecho.cpp: In function 'void setOut(str)':
mecho.cpp:135:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
135 | void setOut(str s) { freopen(s.c_str(),"w",stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
5324 KB |
Output isn't correct |
2 |
Incorrect |
6 ms |
5416 KB |
Output isn't correct |
3 |
Incorrect |
5 ms |
5324 KB |
Output isn't correct |
4 |
Incorrect |
5 ms |
5324 KB |
Output isn't correct |
5 |
Correct |
6 ms |
5412 KB |
Output is correct |
6 |
Incorrect |
6 ms |
5416 KB |
Output isn't correct |
7 |
Incorrect |
98 ms |
6828 KB |
Output isn't correct |
8 |
Incorrect |
7 ms |
5324 KB |
Output isn't correct |
9 |
Correct |
6 ms |
5324 KB |
Output is correct |
10 |
Correct |
7 ms |
5412 KB |
Output is correct |
11 |
Correct |
6 ms |
5412 KB |
Output is correct |
12 |
Incorrect |
8 ms |
5324 KB |
Output isn't correct |
13 |
Incorrect |
8 ms |
5424 KB |
Output isn't correct |
14 |
Correct |
8 ms |
5324 KB |
Output is correct |
15 |
Incorrect |
7 ms |
5324 KB |
Output isn't correct |
16 |
Correct |
7 ms |
5324 KB |
Output is correct |
17 |
Incorrect |
7 ms |
5336 KB |
Output isn't correct |
18 |
Correct |
7 ms |
5412 KB |
Output is correct |
19 |
Incorrect |
7 ms |
5412 KB |
Output isn't correct |
20 |
Correct |
6 ms |
5324 KB |
Output is correct |
21 |
Incorrect |
7 ms |
5416 KB |
Output isn't correct |
22 |
Correct |
7 ms |
5324 KB |
Output is correct |
23 |
Incorrect |
7 ms |
5324 KB |
Output isn't correct |
24 |
Correct |
7 ms |
5408 KB |
Output is correct |
25 |
Incorrect |
8 ms |
5324 KB |
Output isn't correct |
26 |
Correct |
8 ms |
5324 KB |
Output is correct |
27 |
Incorrect |
8 ms |
5324 KB |
Output isn't correct |
28 |
Correct |
8 ms |
5412 KB |
Output is correct |
29 |
Incorrect |
8 ms |
5324 KB |
Output isn't correct |
30 |
Correct |
8 ms |
5416 KB |
Output is correct |
31 |
Incorrect |
8 ms |
5416 KB |
Output isn't correct |
32 |
Correct |
8 ms |
5344 KB |
Output is correct |
33 |
Incorrect |
10 ms |
5580 KB |
Output isn't correct |
34 |
Correct |
11 ms |
5548 KB |
Output is correct |
35 |
Correct |
29 ms |
5580 KB |
Output is correct |
36 |
Incorrect |
12 ms |
5708 KB |
Output isn't correct |
37 |
Correct |
13 ms |
5708 KB |
Output is correct |
38 |
Correct |
35 ms |
5676 KB |
Output is correct |
39 |
Incorrect |
13 ms |
5708 KB |
Output isn't correct |
40 |
Correct |
14 ms |
5816 KB |
Output is correct |
41 |
Correct |
45 ms |
5808 KB |
Output is correct |
42 |
Incorrect |
14 ms |
5916 KB |
Output isn't correct |
43 |
Correct |
14 ms |
5804 KB |
Output is correct |
44 |
Correct |
55 ms |
5908 KB |
Output is correct |
45 |
Incorrect |
14 ms |
6020 KB |
Output isn't correct |
46 |
Correct |
15 ms |
6028 KB |
Output is correct |
47 |
Correct |
58 ms |
6024 KB |
Output is correct |
48 |
Incorrect |
15 ms |
6156 KB |
Output isn't correct |
49 |
Correct |
16 ms |
6152 KB |
Output is correct |
50 |
Correct |
70 ms |
6156 KB |
Output is correct |
51 |
Incorrect |
16 ms |
6220 KB |
Output isn't correct |
52 |
Correct |
16 ms |
6220 KB |
Output is correct |
53 |
Correct |
87 ms |
6340 KB |
Output is correct |
54 |
Incorrect |
17 ms |
6348 KB |
Output isn't correct |
55 |
Correct |
17 ms |
6316 KB |
Output is correct |
56 |
Correct |
101 ms |
6348 KB |
Output is correct |
57 |
Incorrect |
17 ms |
6476 KB |
Output isn't correct |
58 |
Correct |
18 ms |
6564 KB |
Output is correct |
59 |
Correct |
116 ms |
6476 KB |
Output is correct |
60 |
Incorrect |
19 ms |
6720 KB |
Output isn't correct |
61 |
Correct |
20 ms |
6716 KB |
Output is correct |
62 |
Correct |
137 ms |
6724 KB |
Output is correct |
63 |
Correct |
109 ms |
6708 KB |
Output is correct |
64 |
Correct |
202 ms |
6628 KB |
Output is correct |
65 |
Correct |
154 ms |
6604 KB |
Output is correct |
66 |
Incorrect |
141 ms |
6712 KB |
Output isn't correct |
67 |
Correct |
116 ms |
6708 KB |
Output is correct |
68 |
Correct |
53 ms |
6732 KB |
Output is correct |
69 |
Correct |
53 ms |
6756 KB |
Output is correct |
70 |
Correct |
39 ms |
6732 KB |
Output is correct |
71 |
Correct |
45 ms |
6736 KB |
Output is correct |
72 |
Incorrect |
36 ms |
6732 KB |
Output isn't correct |
73 |
Incorrect |
45 ms |
7020 KB |
Output isn't correct |
74 |
Correct |
63 ms |
6988 KB |
Output is correct |
75 |
Correct |
72 ms |
7020 KB |
Output is correct |
76 |
Correct |
65 ms |
7020 KB |
Output is correct |
77 |
Correct |
68 ms |
6956 KB |
Output is correct |
78 |
Correct |
80 ms |
6948 KB |
Output is correct |
79 |
Correct |
52 ms |
6960 KB |
Output is correct |
80 |
Correct |
65 ms |
6988 KB |
Output is correct |
81 |
Correct |
73 ms |
6988 KB |
Output is correct |
82 |
Correct |
62 ms |
6988 KB |
Output is correct |
83 |
Correct |
81 ms |
6860 KB |
Output is correct |
84 |
Correct |
75 ms |
6960 KB |
Output is correct |
85 |
Correct |
86 ms |
6980 KB |
Output is correct |
86 |
Correct |
81 ms |
6940 KB |
Output is correct |
87 |
Correct |
81 ms |
6860 KB |
Output is correct |
88 |
Correct |
84 ms |
6860 KB |
Output is correct |
89 |
Correct |
86 ms |
6860 KB |
Output is correct |
90 |
Correct |
91 ms |
6980 KB |
Output is correct |
91 |
Correct |
94 ms |
6892 KB |
Output is correct |
92 |
Correct |
94 ms |
6860 KB |
Output is correct |