제출 #222022

#제출 시각아이디문제언어결과실행 시간메모리
222022Haunted_CppPohlepko (COCI16_pohlepko)C++17
65 / 80
1100 ms20856 KiB
/* 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 timeMemoryGrader output
Fetching results...