# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
222022 | Haunted_Cpp | Pohlepko (COCI16_pohlepko) | C++17 | 1100 ms | 20856 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.
/*
author: Haunted_Cpp
"Persistence guarantees that results are inevitable"
*/
#include <iostream>
#include <algorithm>
#include <vector>
#pragma GCC optimize ("Ofast")
#pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
using namespace std;
const int N = 2e3 + 5;
char g [N][N];
string coluna [N];
string linha [N], ant_linha [N];
int main () {
ios::sync_with_stdio(0);
cin.tie(0);
int r, c;
cin >> r >> c;
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
cin >> g[i][j];
}
}
coluna[0] = g[0][0];
ant_linha[0] = g[0][0];
for (int i = 1; i < c; i++) {
ant_linha[i] = ant_linha[i - 1] + g[0][i];
}
for (int i = 1; i < r; i++) {
coluna[i] = coluna[i - 1] + g[i][0];
}
for (int i = 1; i < r; i++) {
for (int j = 1; j < c; j++) {
linha[j] = min (ant_linha[j], (j == 1 ? coluna[i] : linha[j - 1])) + g[i][j];
}
for (int j = 1; j < c; j++) {
ant_linha[j] = linha[j];
}
}
if (r == 1) cout << ant_linha[c - 1] << '\n';
else if (c == 1) cout << coluna[r - 1] << '\n';
else cout << linha[c - 1] << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |