Skip to content

Commit 7484e87

Browse files
Add files via upload
1 parent 5a0b0f3 commit 7484e87

File tree

2 files changed

+128
-0
lines changed

2 files changed

+128
-0
lines changed

Other_Tasks/CF2055_C_The_Trail.cpp

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#pragma GCC optimize("Ofast")
2+
#pragma GCC optimize("unroll-loops")
3+
#include <bits/stdc++.h>
4+
using namespace std;
5+
6+
typedef long long ll;
7+
8+
int h, w;
9+
vector<vector<ll>> grid;
10+
int main(){
11+
int tc;
12+
cin >> tc;
13+
while(tc--){
14+
cin >> h >> w;
15+
grid.assign(h, vector<ll>(w, 0));
16+
vector<ll> rowSum(h, 0);
17+
vector<ll> colSum(w, 0);
18+
19+
vector<char> path(w + h-1, '_'); // dummy char in the end
20+
for (int i = 0; i< w + h - 2; i++){
21+
cin >> path[i];
22+
}
23+
24+
for (int i = 0; i < h; i++){
25+
for (int j = 0; j < w; j++){
26+
cin >> grid[i][j];
27+
rowSum[i] += grid[i][j];
28+
colSum[j] += grid[i][j];
29+
}
30+
}
31+
32+
int r = 0;
33+
int c = 0;
34+
int idx = 0;
35+
36+
while (idx < w + h - 1){
37+
assert(r < h && c < w);
38+
if (path[idx] == 'R'){ // we just care about the column
39+
ll v = -colSum[c];
40+
colSum[c] = 0;
41+
rowSum[r] += v;
42+
43+
grid[r][c] = v;
44+
c++;
45+
}
46+
else{
47+
ll v = -rowSum[r];
48+
rowSum[r] = 0;
49+
colSum[c] += v;
50+
51+
grid[r][c] = v;
52+
r++;
53+
}
54+
idx++;
55+
56+
}
57+
58+
for (int i = 0; i < h; i++){
59+
for (int j = 0; j < w; j++){
60+
cout << grid[i][j] << " ";
61+
}
62+
cout << endl;
63+
}
64+
65+
}
66+
67+
return 0;
68+
}

Other_Tasks/CF2055_D_Scarecrow.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// The main difficulty is in doing everything with the numbers multiplied by 2 to avoid having to deal with floating point numbers...
2+
#pragma GCC optimize("Ofast")
3+
#pragma GCC optimize("unroll-loops")
4+
#include <bits/stdc++.h>
5+
using namespace std;
6+
7+
typedef long long ll;
8+
int main(){
9+
int tc;
10+
cin >> tc;
11+
while (tc--){
12+
ll n, k, l;
13+
cin >> n >> k >> l;
14+
15+
vector<ll> a(n);
16+
for (int i = 0; i < n; i++){
17+
cin >> a[i];
18+
a[i] *= 2;
19+
}
20+
l *= 2;
21+
k *= 2;
22+
23+
if (l == 0) {
24+
cout << 0 << endl;
25+
continue;
26+
}
27+
28+
ll ans = a[0]; // two times the amount of time passed
29+
ll pos = k; // two times the position of the crow
30+
31+
for (int i=1; i<n; i++){
32+
if (pos >= l) break;
33+
if (a[i] <= pos){
34+
ll x = min(pos, a[i] + ans);
35+
pos = x + k;
36+
}
37+
else{
38+
if (a[i] - pos <= ans){
39+
pos = pos + k;
40+
}
41+
else{
42+
ll y = a[i] - ans;
43+
assert( y % 2 == pos % 2);
44+
ll moveBy = (y - pos) / 2;
45+
ans += moveBy;
46+
pos = (y - moveBy) + k;
47+
48+
}
49+
}
50+
}
51+
52+
if (pos < l){
53+
ans += l-pos;
54+
}
55+
56+
cout << ans << endl;
57+
}
58+
59+
return 0;
60+
}

0 commit comments

Comments
 (0)