fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long
  5. #define pb push_back
  6. #define pii pair<int, int>
  7. #define pll pair<ll, ll>
  8. #define vvi vector<vector<int>>
  9. #define vt vector
  10. #define arr array
  11. #define ALL(x) begin(x), end(x)
  12. #define rALL(x) rbegin(x), rend(x)
  13. #define SZ(x) x.size()
  14. const int MOD1=998244353;
  15. const int MOD2=1e9+7;
  16. const ll LINF=1e18;
  17. const int INF=1e9;
  18.  
  19. int main(){
  20. ios::sync_with_stdio(0);
  21. cin.tie(0); cout.tie(0);
  22.  
  23. int n, m;
  24. cin>>n>>m;
  25. vt<vt<int>> a(n, vt<int>(m, 0)), dp(n, vt<int>(m));
  26.  
  27. for (int i=0; i<n; i++){
  28. for (int j=0; j<m; j++){
  29. cin>>a[i][j];
  30. if (i && j) dp[i][j]=(a[i][j]>max(a[i-1][j], a[i][j-1]));
  31. else if (i) dp[i][j]=(a[i][j]>a[i-1][j]);
  32. else if (j) dp[i][j]=(a[i][j]>a[i][j-1]);
  33. dp[i][j]++;
  34. cout<<dp[i][j]<<' ';
  35. }
  36. cout<<'\n';
  37. }
  38.  
  39. return 0;
  40. }
Success #stdin #stdout 0s 5300KB
stdin
5 5
2 1 4 3 5
2 4 3 3 1
3 1 2 4 5
2 3 4 5 1
3 4 2 6 5
stdout
1 1 2 1 2 
1 2 1 1 1 
2 1 1 2 2 
1 2 2 2 1 
2 2 1 2 1