fork download
  1. #include <bits/stdc++.h>
  2. #define fi first
  3. #define se second
  4. #define ll long long
  5. using namespace std;
  6. const ll maxll = 9223372036854775806;
  7. const ll modd = 1000000007;
  8. ll arr[1002][1002];
  9. ll N, M, K, a;
  10.  
  11. long long GCD(long long a, long long b) {
  12. if (b == 0) {
  13. return a;
  14. } else {
  15. return GCD(b, a%b);
  16. }
  17. }
  18.  
  19. long long fact(long long a) {
  20. if (a == 0) {
  21. return 1;
  22. } else {
  23. return (a*fact(a-1))%(modd);
  24. }
  25. }
  26.  
  27. void swap(long long *a, long long *b) {
  28. long long c = *a;
  29. *a = *b;
  30. *b = c;
  31. }
  32.  
  33. ll drop(ll height, ll position) {
  34. if (height == N) {
  35. return position+1;
  36. } else {
  37. if (arr[height][position] == 1) {
  38. arr[height][position] = 2;
  39. return drop(height, position+1);
  40. } else if (arr[height][position] == 3) {
  41. arr[height][position] = 2;
  42. return drop(height, position-1);
  43. } else {
  44. return drop(height+1, position);
  45. }
  46. }
  47. }
  48.  
  49. int main() {
  50. ios_base::sync_with_stdio();
  51. cin.tie(0); cout.tie(0);
  52. cin >> N >> M >> K;
  53. for (ll i = 0; i < N; i++) {
  54. for (ll j = 0; j < M; j++) {
  55. cin >> arr[i][j];
  56. }
  57. }
  58. for (ll i = 0; i < K; i++) {
  59. cin >> a;
  60. cout << drop(0, a-1);
  61. if (i != K-1) {
  62. cout << ' ';
  63. } else {
  64. cout << endl;
  65. }
  66. }
  67. return 0;
  68. // delete return 0; to do some testing below
  69. return 0;
  70. }
  71.  
  72. // Made by: AndreaSonic
  73.  
  74. // Notes:
  75. // If the result is too high, pow function might use "e+[n]", which might make the judging failed
Success #stdin #stdout 0s 5460KB
stdin
5 5 3
1 2 3 3 3
2 2 2 2 2
2 2 2 2 2
2 2 2 2 2
2 2 2 2 2
1 2 1
stdout
2 2 1