제출 #720682

#제출 시각아이디문제언어결과실행 시간메모리
720682Yell0Pohlepko (COCI16_pohlepko)C++17
80 / 80
86 ms8124 KiB
#include <bits/stdc++.h>

using namespace std;
typedef pair<int,int> pii;
const int MN=2002;
int N,M;
char grid[MN][MN];
set<pii> ol,nl;
string ans="";

int main() {
    ios::sync_with_stdio(0);cin.tie(0);
    cin>>N>>M;
    string in;
    for(int i=1;i<=N;i++) {
        cin>>in;
        for(int j=1;j<=M;j++)
            grid[i][j]=in[j-1];
    }
    ol.insert({1,1});
    ans+=grid[1][1];
    for(int i=1;i<N+M-1;i++) {
        char opt='|';
        for(pii p:ol) {
            char d=grid[p.first+1][p.second],r=grid[p.first][p.second+1];
            if(p.first+1<=N) {
                if(d<opt) {
                    opt=d;
                    nl.clear();
                    nl.insert({p.first+1,p.second});
                } else if(d==opt) nl.insert({p.first+1,p.second});
            }
            if(p.second+1<=M) {
                if(r<opt) {
                    opt=r;
                    nl.clear();
                    nl.insert({p.first,p.second+1});
                } else if(r==opt) nl.insert({p.first,p.second+1});
            }
        }
        ans+=opt;
        ol=nl;
        nl.clear();
    }
    cout<<ans<<'\n';
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...