Submission #1312688

#TimeUsernameProblemLanguageResultExecution timeMemory
1312688rodolfovertoPohlepko (COCI16_pohlepko)C++20
80 / 80
129 ms4392 KiB
#include <bits/stdc++.h> #define space ' ' #define endl '\n' #define F first #define S second #define int long long #define pd pair <int,int> using namespace std; int32_t main(){ int n,m; cin >> n >> m; vector< vector <char> >mat(n,vector <char>(m)); for(int i=0; i<n; i++){ for(int j=0; j<m; j++){ cin >> mat[i][j]; } } queue<pd>q; string res; res.push_back(mat[0][0]); q.push({0,0}); while(q.front().F != n-1 || q.front().S != m-1){ set<pd>s; stack<pd>pos,us; while(!q.empty()){ int x,y; x=q.front().F; y=q.front().S; q.pop(); if(x+1 != n){ s.insert({x+1,y}); } if(y+1 != m){ s.insert({x,y+1}); } } for(auto &i: s){ if(pos.empty() || mat[pos.top().F][pos.top().S] == mat[i.F][i.S]){ pos.push(i); }else if(mat[pos.top().F][pos.top().S]-'a'>mat[i.F][i.S]-'a'){ pos=us; pos.push(i); } } res.push_back(mat[pos.top().F][pos.top().S]); while(!pos.empty()){ q.push(pos.top()); pos.pop(); } } cout << res << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...