Skip to content

Commit b9c95b2

Browse files
committed
[codeforces - 1517] Add C++ solution for C - Fillomino 2.
1 parent 2d3c166 commit b9c95b2

File tree

6 files changed

+49
-0
lines changed

6 files changed

+49
-0
lines changed

codeforces/1517/c-1.ans

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2
2+
2 3
3+
3 3 1

codeforces/1517/c-1.in

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
3
2+
2 3 1

codeforces/1517/c-2.ans

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
1
2+
2 2
3+
3 3 3
4+
4 4 4 4
5+
5 5 5 5 5

codeforces/1517/c-2.in

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
5
2+
1 2 3 4 5

codeforces/1517/c.cc

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// https://codeforces.com/contest/1517/problem/C
2+
#include <bits/stdc++.h>
3+
4+
using namespace std;
5+
const int N = 505;
6+
int xs[N][N];
7+
8+
int main() {
9+
cin.tie(0), ios::sync_with_stdio(0);
10+
int n;
11+
cin >> n;
12+
for (int i = 0; i < n; i++) cin >> xs[i][i];
13+
for (int ii = 0; ii < n; ii++) {
14+
int k = xs[ii][ii];
15+
int dy[4] = {0, 1, 0, -1};
16+
int dx[4] = {-1, 0, 1, 0};
17+
int y = ii, x = ii;
18+
for (int j = 1; j < k; j++)
19+
for (int i = 0; i < 4; i++) {
20+
int yy = y + dy[i], xx = x + dx[i];
21+
if (yy >= 0 && yy < n && xx >= 0 && xx < n && !xs[yy][xx]) {
22+
xs[yy][xx] = k;
23+
y = yy, x = xx;
24+
break;
25+
}
26+
}
27+
}
28+
for (int i = 0; i < n; i++)
29+
for (int j = 0; j <= i; j++)
30+
if (!xs[i][j]) {
31+
cout << "-1\n";
32+
return 0;
33+
}
34+
for (int i = 0; i < n; i++)
35+
for (int j = 0; j <= i; j++) cout << xs[i][j] << " \n"[j == i];
36+
}

codeforces/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
There are solutions for the following [codeforces](http://codeforces.com/) problems:
44

55
### Contests ([problemset site](https://codeforces.com/problemset))
6+
1. [1517C - Fillomino 2](1517/c.cc) ([problem site](https://codeforces.com/contest/1517/problem/C))
67
1. [1517B - Morning Jogging](1517/b.cc) ([problem site](https://codeforces.com/contest/1517/problem/B))
78
1. [1517A - Sum of 2050](1517/a.cc) ([problem site](https://codeforces.com/contest/1517/problem/A))
89
1. [1500B - Two chandeliers](1501/d.cc) ([problem site](https://codeforces.com/contest/1500/problem/B))

0 commit comments

Comments
 (0)