fork download
  1. //Collecting the dream I threw away
  2. //Road to VOI
  3. #include<bits/stdc++.h>
  4. #define el '\n'
  5. #define ll long long
  6. #define ull unsigned long long
  7. #define fumo ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  8. #define pb push_back
  9. #define str string
  10. #define sz(v) (int)v.size()
  11. #define ldb long double
  12. #define db double
  13. #define reimu(v) v.begin(), v.end()
  14. #define ret return
  15. #define fi first
  16. #define se second
  17. #define int long long
  18. using namespace std;
  19. #pragma GCC optimize ("Ofast")
  20. #pragma GCC optimize ("unroll-loops")
  21. #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
  22. //ᗜˬᗜ
  23. const int N=2e2+7,base=37,block=280;
  24. const ll mod=1e9+7,inf=1e18;
  25. int n,m;
  26. char S[N][N],tmp[N][N];
  27.  
  28. void sol()
  29. {
  30. cin>>n>>m;
  31. for(int i=1;i<=n;++i) for(int j=1;j<=m;++j) cin>>S[i][j];
  32. for(int j=1;j<=m;++j) S[0][j]='0';
  33. for(int i=0;i<=n;++i) for(int j=1;j<=m;++j) tmp[i][j]=S[i][j];
  34. for(int i=1;i<=n;++i)
  35. {
  36. int last=m+1;
  37. for(int j=1;j<=m;++j) if(tmp[i][j]!='.' && tmp[i][j]!=tmp[i-1][j])
  38. {
  39. last=j;
  40. break;
  41. }
  42. bool smaller=1;
  43. if(last<=m) if(tmp[i-1][last]>tmp[i][last]) smaller=0;
  44. //cout<<last<<el;
  45. if(last<=m && !smaller) for(int j=last-1;j>=1;--j) if(tmp[i][j]=='.')
  46. {
  47. if(tmp[i-1][j]=='1') continue;
  48. tmp[i][j]='1';
  49. last=j;
  50. break;
  51. }
  52. for(int j=last-1;j>=1;--j) if(tmp[i][j]=='.') tmp[i][j]=tmp[i-1][j];
  53. for(int j=last+1;j<=m;++j) if(tmp[i][j]=='.') tmp[i][j]='0';
  54. //cout<<last<<el;
  55. //for(int j=1;j<=m;++j) cout<<tmp[i][j];cout<<el;
  56. for(int j=1;j<=m;++j) if(tmp[i-1][j]!=tmp[i][j])
  57. {
  58. if(tmp[i-1][j]>tmp[i][j])
  59. {
  60. cout<<-1;
  61. ret;
  62. }
  63. break;
  64. }
  65. }
  66. for(int j=1;j<=m;++j) cout<<tmp[n][j];cout<<el;
  67. }
  68.  
  69. void ffopen(const str &alice)
  70. {
  71. if(fopen((alice+".inp").c_str(), "r")){
  72. freopen((alice+".inp").c_str(), "r", stdin);
  73. freopen((alice+".out").c_str(), "w", stdout);
  74. }
  75. }
  76.  
  77. signed main()
  78. {
  79. fumo
  80. ffopen("");
  81. int t=1;
  82. //cin>>t;
  83. while(t--) sol();
  84. ret 0;
  85. }
  86.  
Success #stdin #stdout 0s 5304KB
stdin
Standard input is empty
stdout