Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3f0755b

Browse files
new problem from neps
1 parent 02ff972 commit 3f0755b

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <iostream>
2+
3+
using namespace std;
4+
5+
int main() {
6+
7+
int n, x, mm = 0, pp = 0, m, p;
8+
cin >> n;
9+
for (int i = 1; i <= n; i++) {
10+
cin >> x;
11+
if (x == 1)
12+
pp++;
13+
else
14+
mm++;
15+
}
16+
17+
cin >> p >> m;
18+
19+
if (p == pp && mm == m)
20+
cout << "S\n";
21+
else
22+
cout << "N\n";
23+
24+
return 0;
25+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#include <iostream>
2+
#include <vector>
3+
4+
using namespace std;
5+
6+
// description of the problem: https://neps.academy/br/exercise/57
7+
8+
vector<vector<int > > v, vi;
9+
10+
int cont = 0, resp = 0;
11+
12+
void contPathStars(int x, int y) {
13+
if (!vi[x][y]) {
14+
vi[x][y] = 1;
15+
cont+=1;
16+
17+
if (v[x][y] == 3)
18+
resp = cont;
19+
// first left, right then up and down
20+
int vert[4] = {-1, 1, 0, 0};
21+
int hori[4] = {0, 0, -1, 1};
22+
23+
for (int i = 0; i < 4; i++) {
24+
// verify if it was already seen
25+
if (vert[i] + x >= 0 && vert[i] + x < (int)v.size() && // if is in the range of rows
26+
hori[i] + y >= 0 && hori[i] + y < (int)v[0].size() && // if is in the range of cols
27+
!vi[vert[i] + x][hori[i] + y] && // if it was not visited
28+
(v[vert[i]+x][hori[i] + y] == 1 ||
29+
v[vert[i]+x][hori[i] + y] == 3)
30+
) {
31+
contPathStars(vert[i]+x, hori[i] + y);
32+
}
33+
}
34+
}
35+
cont--;
36+
}
37+
38+
int main () {
39+
40+
int n, m, xStart = 0, yStart = 0;
41+
42+
cin >> n >> m;
43+
44+
v.assign(n, vector<int>(m, 0));
45+
vi.assign(n, vector<int>(m, 0));
46+
47+
for(int i = 0; i < n; i++) {
48+
for (int j = 0; j < m; j++) {
49+
cin >> v[i][j];
50+
if (v[i][j] == 2) {
51+
xStart = i;
52+
yStart = j;
53+
}
54+
}
55+
}
56+
57+
contPathStars(xStart, yStart);
58+
cout << resp << endl;
59+
return 0;
60+
}
61+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /