fork download
  1. program cestini;
  2. { NOTA: si raccomanda di usare questo template anche se non lo si capisce completamente }
  3.  
  4. const
  5. MAX = 100000;
  6.  
  7. var
  8. M, N, Q, T, i, test : LongInt;
  9. S, ans : AnsiString;
  10. qtype : Array[0..MAX-1] of Char;
  11. a, b , lung : Array[0..MAX-1] of LongInt;
  12.  
  13. v: array of array of longint;
  14.  
  15.  
  16. procedure inizia (N:Longint; M:Longint) ;
  17. var j:longint;
  18. begin
  19. setLength(V, M);
  20. for j:=0 to high(V) do begin setLength(V[j], 1); end;
  21. lung[0]:=N-1;
  22. for j:=1 to M-1 do lung[j]:= 0;
  23. end;
  24.  
  25. Procedure sposta (a:Longint;b:Longint);
  26. begin
  27. V[b][lung[b]]:=V[a][lung[a]];
  28. lung[a]:=lung[a]-1;
  29. lung[b]:=lung[b]+1;
  30. end;
  31.  
  32. function controlla (a:Longint;i:Longint) : longint;
  33.  
  34. begin
  35. if lung[a]<=i then controlla:=-1
  36. else controlla:=V[a][i];
  37. writeln(controlla) ;
  38.  
  39. end;
  40.  
  41.  
  42. begin
  43. {
  44.   decommenta le due righe seguenti se vuoi leggere/scrivere da file
  45.   assign(input, 'input.txt'); reset(input);
  46.   assign(output, 'output.txt'); rewrite(output);
  47. }
  48.  
  49. ReadLn(N, M, Q);
  50. for i:=0 to Q-1 do
  51. ReadLn(qtype[i], a[i], b[i]);
  52. ans := '';
  53. inizia(N,M);
  54. for i:=0 to Q-1 do
  55. begin
  56. if qtype[i]='s' then sposta(a[i],b[i])
  57. else if qtype[i]='c' then controlla(a[i],b[i]);
  58. end;
  59.  
  60. end.
  61.  
Success #stdin #stdout 0s 5316KB
stdin
5 6 7
s 0 1
c 1 0
s 0 2
s 1 2
s 0 2
c 2 2
c 2 1
stdout
1
360481
0