Submission #883668

# Submission time Handle Problem Language Result Execution time Memory
883668 2023-12-05T16:27:04 Z vjudge1 Pohlepko (COCI16_pohlepko) C++17
40 / 80
85 ms 65536 KB
#include <bits/stdc++.h>
using namespace std;
#define sp << " " << 
#define int long long
#define vi vector<int>
#define F(xxx,yyy) for (int xxx=1;xxx<=yyy;xxx++)
#define pii pair<int,int>
const int N = 1e5+1;

void solve() {
  int n,m;
  cin >> n >> m;
  char grid[n+1][m+1];
  F(i,n){
    string s;
    cin >> s;
    F(j,m) grid[i][j] = s[j-1];
  }
  queue<pair<pii,int>> q;
  string s;
  cin >> s;
  F(i,n+m-1) s+='z';
  q.push({{1,1},0});
  while (!q.empty()) {
    auto f= q.front();
    q.pop();
    int c = f.second;
    int x = f.first.first;
    int y = f.first.second;
    if (s[c] < grid[x][y]) continue;
    s[c] = grid[x][y];
    if (x<n && y<m) {
      if (grid[x+1][y] <= grid[x][y+1]) {
        q.push({{x+1,y},c+1});
      }
      if (grid[x][y+1] <= grid[x+1][y]) {
        q.push({{x,y+1},c+1});
      }
    }
    else {
      if (x < n) q.push({{x+1,y},c+1});
      else if (y<m) q.push({{x,y+1},c+1});
    }
  }
  cout << s << endl;
}
    
                  
                             
signed main() { 
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  #ifdef Local
  freopen("in","r",stdin);
  freopen("out","w",stdout); 
  #endif
  int t = 1;
  //cin >> t;
	F(i,t) solve();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 2 ms 1628 KB Output is correct
8 Correct 5 ms 4188 KB Output is correct
9 Incorrect 0 ms 348 KB Output isn't correct
10 Incorrect 0 ms 348 KB Output isn't correct
11 Incorrect 1 ms 604 KB Output isn't correct
12 Incorrect 1 ms 600 KB Output isn't correct
13 Incorrect 1 ms 604 KB Output isn't correct
14 Incorrect 5 ms 4416 KB Output isn't correct
15 Runtime error 85 ms 65536 KB Execution killed with signal 9
16 Runtime error 82 ms 65536 KB Execution killed with signal 9