Skip to content

Commit 2b36bcf

Browse files
committed
junk
1 parent 8efa1f7 commit 2b36bcf

File tree

2 files changed

+173
-0
lines changed

2 files changed

+173
-0
lines changed

Diff for: codeforces/gym/100796/journey.cpp

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#include <cstdio>
2+
#include <cstring>
3+
#include <algorithm>
4+
#include <utility>
5+
#include <vector>
6+
#include <queue>
7+
8+
using namespace std;
9+
10+
const int MAXN = 505;
11+
12+
const int dx[] = {1, 0, -1, 0};
13+
const int dy[] = {0, -1, 0, 1};
14+
15+
int n, m;
16+
int a, b;
17+
// true means you can walk there
18+
bool grid[MAXN][MAXN];
19+
20+
char row[MAXN];
21+
22+
struct state {
23+
int x, y, dist;
24+
bool is_town;
25+
26+
bool operator<(const state& other) const {
27+
return other.dist < dist;
28+
}
29+
};
30+
31+
inline bool in_bounds(int x, int y) {
32+
return 0 <= x and x < n and 0 <= y and y < m;
33+
}
34+
35+
void read() {
36+
scanf("%d %d", &m, &n);
37+
scanf("%d %d", &a, &b);
38+
memset(grid, false, sizeof(grid));
39+
40+
for (int i = 0; i < n; ++i) {
41+
scanf("%s", row);
42+
for (int j = 0; j < m; ++j) {
43+
grid[i][j] = (row[j] == '.');
44+
}
45+
}
46+
47+
/*
48+
for (int i = 0; i < n; ++i) {
49+
for (int j = 0; j < m; ++j) {
50+
printf("%d", grid[i][j]);
51+
}
52+
puts("");
53+
}
54+
*/
55+
}
56+
57+
void solve() {
58+
if (!grid[0][0] or !grid[n - 1][m - 1]) {
59+
puts("IMPOSSIBLE");
60+
return;
61+
}
62+
63+
state start = {0, 0, 0, true};
64+
priority_queue<state> pq;
65+
pq.push(start);
66+
67+
while (!pq.empty()) {
68+
state cur = pq.top();
69+
pq.pop();
70+
71+
if (cur.x == n - 1 and cur.y == m - 1) {
72+
printf("%d\n", cur.dist);
73+
return;
74+
}
75+
76+
if (!grid[cur.x][cur.y]) continue;
77+
78+
grid[cur.x][cur.y] = false;
79+
80+
for (int d = 0; d < 4; ++d) {
81+
int nx = cur.x + dx[d];
82+
int ny = cur.y + dy[d];
83+
if (in_bounds(nx, ny) and grid[nx][ny]) {
84+
state next_state = {nx, ny, cur.dist + (cur.is_town ? b : a), !cur.is_town};
85+
pq.push(next_state);
86+
}
87+
}
88+
}
89+
90+
puts("IMPOSSIBLE");
91+
}
92+
93+
int main() {
94+
read();
95+
solve();
96+
return 0;
97+
}

Diff for: hackerrank/cube_summation.cpp

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#include <cstdio>
2+
#include <cstring>
3+
4+
using namespace std;
5+
6+
const int MAXN = 102;
7+
int n, m;
8+
long long f_tree[MAXN][MAXN][MAXN];
9+
10+
char command[20];
11+
12+
void update(int x, int y, int z, int v) {
13+
for (int i = x; i < MAXN; i += (i & -i)) {
14+
for (int j = y; j < MAXN; j += (j & -j)) {
15+
for (int k = z; k < MAXN; k += (k & -k)) {
16+
f_tree[i][j][k] += v;
17+
}
18+
}
19+
}
20+
}
21+
22+
long long query(int x, int y, int z) {
23+
long long ans = 0;
24+
for (int i = x; i > 0; i -= (i & -i)) {
25+
for (int j = y; j > 0; j -= (j & -j)) {
26+
for (int k = z; k > 0; k -= (k & -k)) {
27+
ans += f_tree[i][j][k];
28+
}
29+
}
30+
}
31+
32+
return ans;
33+
}
34+
35+
long long query(int x1, int y1, int z1, int x2, int y2, int z2) {
36+
long long ans = query(x2, y2, z2);
37+
ans -= query(x1 - 1, y2, z2);
38+
ans -= query(x2, y1 - 1, z2);
39+
ans -= query(x2, y2, z1 - 1);
40+
41+
ans += query(x2, y1 - 1, z1 - 1);
42+
ans += query(x1 - 1, y2, z1 - 1);
43+
ans += query(x1 - 1, y1 - 1, z2);
44+
45+
ans -= query(x1 - 1, y1 - 1, z1 - 1);
46+
47+
return ans;
48+
}
49+
50+
int main() {
51+
int T;
52+
scanf("%d", &T);
53+
54+
int x1, y1, z1, x2, y2, z2, v;
55+
while (T-- > 0) {
56+
scanf("%d %d", &n, &m);
57+
memset(f_tree, 0, sizeof(f_tree));
58+
59+
while (m-- > 0) {
60+
scanf("%s", command);
61+
62+
if (command[0] == 'U') {
63+
scanf("%d %d %d %d", &x1, &y1, &z1, &v);
64+
long long old_v = query(x1, y1, z1, x1, y1, z1);
65+
update(x1, y1, z1, v - old_v);
66+
} else {
67+
scanf("%d %d %d %d %d %d", &x1, &y1, &z1, &x2, &y2, &z2);
68+
long long ans = query(x1, y1, z1, x2, y2, z2);
69+
70+
printf("%lld\n", ans);
71+
}
72+
}
73+
}
74+
75+
return 0;
76+
}

0 commit comments

Comments
 (0)