# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
98534 | dalgerok | Pohlepko (COCI16_pohlepko) | C++17 | 66 ms | 13836 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int N = 2e3 + 5;
int n, m;
bool used[N][N];
char a[N][N];
vector < pair < int, int > > q[N + N];
inline bool check(int x, int y){
return 1 <= x && x <= n && 1 <= y && y <= m;
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> m;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
cin >> a[i][j];
}
}
q[1 + 1].push_back(make_pair(1, 1));
for(int i = 2; i <= n + m; i++){
cout << a[q[i][0].first][q[i][0].second];
char mn = 'z';
for(auto it : q[i]){
int xx, yy;
xx = it.first + 1, yy = it.second;
if(check(xx, yy)){
mn = min(mn, a[xx][yy]);
}
xx = it.first, yy = it.second + 1;
if(check(xx, yy)){
mn = min(mn, a[xx][yy]);
}
}
for(auto it : q[i]){
int xx, yy;
xx = it.first + 1, yy = it.second;
if(check(xx, yy) && !used[xx][yy] && a[xx][yy] == mn){
used[xx][yy] = true;
q[xx + yy].push_back(make_pair(xx, yy));
}
xx = it.first, yy = it.second + 1;
if(check(xx, yy) && !used[xx][yy] && a[xx][yy] == mn){
used[xx][yy] = true;
q[xx + yy].push_back(make_pair(xx, yy));
}
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |