-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVaisseau spatial 2.cpp
45 lines (37 loc) · 1.04 KB
/
Vaisseau spatial 2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "bits/stdc++.h"
using namespace std;
#define N 2000 + 1
#define M 50
int n, m, p;
int a[N][M];
pair<int, int> getMax(int i, int j) {
pair<int, int> res = make_pair(a[i - 1][j], 0);
// between "stay" and "left", choose "stay"
if (j > 0 && a[i - 1][j - 1] > res.first)
res = make_pair(a[i - 1][j - 1], -1);
// between "left" and "right", choose "left"
// between "stay" and "right", choose "stay"
if (j < m - 1 && a[i - 1][j + 1] > res.first)
res = make_pair(a[i - 1][j + 1], 1);
return res;
}
void print() {
for (int i = 0; i < n + 1; i++) {
for (int j = 0; j < m; j++) cout << setw(2) << a[i][j];
cout << "\n";
}
cout << "\n";
}
int main() {
cin >> n >> m >> p;
for (int i = 0; i < n + 1; i++)
for (int j = 0; j < m; j++) cin >> a[i][j];
for (int i = 1; i < n + 1; i++)
for (int j = 0; j < m; j++) a[i][j] += getMax(i, j).first;
for (int i = n - 1; i > 0; i--) {
auto next = getMax(i, p);
p += next.second;
cout << next.second << " ";
}
return 0;
}