# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
845676 | vjudge1 | Skandi (COCI20_skandi) | C++17 | 118 ms | 680 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define s second
#define f first
typedef long long ll;
const ll MOD = 998244353;
const ll LOGN = 20;
const ll MAXN = 3e5 + 5;
int N, M;
vector<string> grid;
void fillGrid(pair<bool,pair<int,int>> P, vector<string> &new_grid) {
if (P.f) {
pair<int,int> now = {P.s.f, P.s.s + 1};
while (now.s <= M-1 && new_grid[now.f][now.s] == '0') {
new_grid[now.f][now.s] = '1';
now.s++;
}
} else {
pair<int,int> now = {P.s.f + 1, P.s.s};
while (now.f <= N-1 && new_grid[now.f][now.s] == '0') {
new_grid[now.f][now.s] = '1';
now.f++;
}
}
}
int main() {
fast
cin >> N >> M;
grid = vector<string>(N);
for (int i = 0; i < N; i++)
cin >> grid[i];
vector<pair<bool,pair<int,int>>> ones;
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
if (grid[i][j] == '1')
ones.push_back({false, {i, j}});
}
}
int n = ones.size();
for (int i = 0; i < n; i++)
ones.push_back({true, ones[i].s});
const int mx_mask = (1<<ones.size())-1;
int ans = 1e5;
int ans_mask = -1;
for (int mask = 0; mask <= mx_mask; mask++) {
vector<string> new_grid = grid;
for (int i = 0; i < ones.size(); i++) {
if ((1<<i) & mask)
fillGrid(ones[i], new_grid);
}
bool control = true;
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
if (new_grid[i][j] == '0')
control = false;
}
}
if (control && ans > __builtin_popcount(mask)) {
ans = __builtin_popcount(mask);
ans_mask = mask;
}
}
cout << ans << "\n";
for (int i = 0; i < ones.size(); i++) {
if ((1<<i) & ans_mask) {
cout << ones[i].s.f + 1 << " " << ones[i].s.s + 1 << " ";
if (ones[i].f)
cout << "DESNO\n";
else
cout << "DOLJE\n";
}
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |