fork download
  1. #include "bits/stdc++.h"
  2. using namespace std;
  3. typedef int ll;
  4. typedef pair<int ,int> pii;
  5. typedef pair<ll ,ll> pll;
  6. #define F first
  7. #define S second
  8. #define pb push_back
  9. #define mp make_pair
  10. #define all(X) (X).begin(), (X).end()
  11. #define sll(n) scanf("%lld",&n)
  12. #define sll2(x,y) scanf("%lld%lld",&x,&y)
  13. #define sll3(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
  14. #define REP(i,x,y) for(ll i = x;i <= y;++i)
  15. #define debug(x) cerr<<#x<<"::"<<x<<endl
  16. #define debug2(x,y) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n"
  17. #define debug3(x,y,z) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n"
  18. #define debug4(x,y,z,w) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<"\n"
  19. ll power(ll x,ll y,ll z) {
  20. ll ret = 1;
  21. while(y > 0) {
  22. if(y & 1) ret = (ret*x)%z;
  23. x = (x*x)%z;
  24. y >>= 1;
  25. }
  26. return ret;
  27. }
  28. const ll N = 505, M = 105, LG = 32;
  29. pll dp[N][N][M][LG];
  30. string s, A[N];
  31. ll n,m;
  32. pll move(ll x,ll y, char ch) {
  33. ll dx, dy;
  34. if(ch == 'L') dx = 0, dy = -1;
  35. else if(ch == 'R') dx = 0, dy = 1;
  36. else if(ch == 'U') dx = -1, dy = 0;
  37. else if(ch == 'D') dx = 1, dy = 0;
  38. else assert(0);
  39. ll nx = x + dx, ny = y + dy;
  40. if(nx >= 0 && nx < n && ny >= 0 && ny < m && A[nx][ny] == '.') return mp(nx, ny);
  41. return mp(x, y);
  42. }
  43. int main() {
  44.  
  45. ll q;
  46. cin >> n >> m >> q;
  47. REP(i,0,n - 1) cin >> A[i];
  48. cin >> s;
  49. ll sz = s.size();
  50. REP(i,0,n - 1) {
  51. REP(j,0,m - 1) {
  52. if(A[i][j] == '.') {
  53. REP(k,0,sz - 1) {
  54. dp[i][j][k][0] = move(i, j, s[k]);
  55. }
  56. }
  57. }
  58. }
  59. REP(l,1,LG - 1) {
  60. REP(i,0,n - 1) {
  61. REP(j,0,m - 1) {
  62. REP(k,0,sz - 1) {
  63. ll nk = ((1LL << (l - 1)) + k) % sz, ni = dp[i][j][k][l - 1].F, nj = dp[i][j][k][l - 1].S;
  64. dp[i][j][k][l] = dp[ni][nj][nk][l - 1];
  65. }
  66. }
  67. }
  68. }
  69. while(q--) {
  70. ll x,y,z,k = 0;
  71. cin >> x >> y >> z;
  72. --x,--y;
  73. for(ll i = 0;i < LG;++i) {
  74. if((1LL << i) & z) {
  75. auto pp = dp[x][y][k][i];
  76. x = pp.F, y = pp.S;
  77. k = (k + (1LL << i)) % sz;
  78. }
  79. }
  80. cout << x + 1 << " " << y + 1 << "\n";
  81. }
  82.  
  83.  
  84.  
  85. return 0;
  86. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
3 5 2
.....
.....
..#..
LLUR
2 3 2
3 4 6
compilation info
/home/4G1BYb/ccJxme78.o: in function `_GLOBAL__sub_I__Z5poweriii':
prog.cpp:(.text.startup+0x487): relocation truncated to fit: R_X86_64_PC32 against `.bss'
prog.cpp:(.text.startup+0x4a1): relocation truncated to fit: R_X86_64_PC32 against `.bss'
collect2: error: ld returned 1 exit status
stdout
Standard output is empty