fork download
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4. #include <iostream>
  5. #include <cstdlib>
  6. #include <vector>
  7. #include <list>
  8. #include <set>
  9. #include <deque>
  10. #include <utility>
  11. #include <cmath>
  12. #include <string>
  13. #include <cstring>
  14. #include <iomanip>
  15. #include <cctype>
  16. #include <algorithm>
  17. #include <numeric>
  18. #include <queue>
  19. #include <any>
  20. #define Yellow_Flash \
  21.   ios_base::sync_with_stdio(0); \
  22.   cin.tie(0); \
  23.   cout.tie(0)
  24. #define pi 3.14159265358979323
  25. #define el "\n"
  26. #define ll long long
  27. #define sp ' '
  28. #define MAX INT_MAX
  29. #define MIN INT_MIN
  30. #define all(_) _.begin(),_.end()
  31. #define rall(_) _.rbegin(),_.rend()
  32. #define input(_) for(auto & i : _) cin >> i;
  33. #define input2(_) for(auto & i : _) for(auto &j : i) cin >> j;
  34. #define output(_) for(auto & i : _) cout << i << sp;
  35. #define output2(_) for(auto & i : _) for(auto &j : i) cout << j << sp;
  36. #define uniq(_) _.erase(unique(all(_)), _.end())
  37. #define point(_) cout << fixed << setprecision(_);
  38.  
  39.  
  40. using namespace std;
  41. // using namespace __gnu_pbds;
  42.  
  43. // typedef tree<int, null_type, greater<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
  44.  
  45. void YelloW_Flash(){
  46. #ifndef ONLINE_JUDGE
  47. freopen("input.txt", "r", stdin);
  48. freopen("output.txt", "w", stdout);
  49. #endif
  50. Yellow_Flash;
  51. }
  52.  
  53. bool comp(string &a, string & b)
  54. {
  55. if(a.size()==b.size()) return a<b;
  56. return a.size()<b.size();
  57. }
  58.  
  59. ll fixmod(ll a, ll b){
  60. return (a%b+b)%b;
  61. }
  62. const int sz1=1e2+5,sz2=1e2+5;
  63. ll dp[sz1][sz2];
  64. ll n, m;
  65. // vector<ll> v;
  66. set<pair<ll,ll>> idx;
  67. ll rec (ll i=1, ll j=1){
  68. if(i>n || j>m || (!idx.empty() && idx.count({i,j}))) return 0;
  69. if(i==n && j==m) return 1;
  70. ll & ret = dp[i][j];
  71. if(ret!=-1) return ret;
  72. ll ch1=rec(i+1,j);
  73. ll ch2=rec(i,j+1);
  74. return ret=ch1+ch2;
  75. }
  76.  
  77.  
  78.  
  79. int main()
  80. {
  81. YelloW_Flash();
  82. ll T=1;
  83. cin >> T;
  84. while(T--){
  85. memset(dp,-1LL, sizeof(dp));
  86. idx.clear();
  87. string s;
  88. getline(cin,s);
  89. cin >> n >> m;
  90. getline(cin,s);
  91. for(int i=1; i<=n; ++i){
  92. string x, num;
  93. getline(cin,x);
  94. for(int j=log(i)+1; j<x.size(); ++j){
  95. if(isdigit(x[j])) num+=x[j];
  96. else {
  97. if(!num.empty()) {
  98. ll numm=stoll(num);
  99. idx.insert({i,numm});
  100. }
  101. num.clear();
  102. }
  103. }
  104. if(!num.empty()) {
  105. ll numm=stoll(num);
  106. idx.insert({i,numm});
  107. }
  108. num.clear();
  109. }
  110. for(auto &[i,j]: idx) cout << i << sp << j << el;
  111. cout << rec() << el;
  112. cout << el;
  113. }
  114. return 0;
  115. }
  116.  
  117. /* Fight not to be the Winner ,but to be the last one to lose */
  118.  
Success #stdin #stdout 0s 5312KB
stdin
Standard input is empty
stdout
0