Advertisement
Rofyda_Elghadban1

Untitled

Oct 3rd, 2023
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define ull unsigned long long
  4. #define pi 3.141592654
  5. #define NUM 1e18
  6. #define Mod 1'000'000'007
  7. #define fixed(n) fixed<<setprecision(n)
  8. #define cin(v) for(auto &i:v) cin >> i ;
  9. #define cout(v) for(auto &i:v) cout << i <<" ";
  10. #define vowel(x) (x=='e'||x=='a'||x=='i'||x=='o'||x=='u')
  11. #define small(x) (x>=97&&x<=122)
  12. #define capital(x) (x>=65&&x<=90)
  13. #define Tolower(s) transform(s.begin(),s.end(),s.begin(),::tolower);
  14. #define Toupper(s) transform(s.begin(),s.end(),s.begin(),::toupper);
  15. #define all(v) ((v).begin()), ((v).end())
  16. #define allr(v) ((v).rbegin()), ((v).rend())
  17. #define updmax(a,b) a=max(a,b)
  18. #define updmin(a,b) a=min(a,b)
  19. #define ceil(a,b) ((a/b)+(a%b?1:0))
  20. /* asc -> 1 2 3 ,des -> 3 2 1 */
  21. /***********************************************************************************/
  22. using namespace std;
  23. void Rofyda_Elghadban(){
  24. #ifndef ONLINE_JUDGE
  25. freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  26. #endif
  27. ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  28. }
  29.  
  30. struct com{
  31. bool operator()(int l,int r){
  32. return (l>=50)<(r>=50);
  33. }
  34. };
  35.  
  36. void solve(){
  37. int n,counter=0;
  38. cin>>n;
  39. int c1;
  40. cin>>c1;
  41. deque<int>d1(c1),dd1(c1);
  42. cin(d1);
  43. dd1=d1;
  44. int c2;
  45. cin>>c2;
  46. deque<int>d2(c2),dd2(c2);
  47. cin(d2);
  48. dd2=d2;
  49. while(d1.size()>0&&d2.size()>0){
  50. if(d1.front()<d2.front()){
  51. d2.push_back(d1.front());
  52. d2.push_back(d2.front());
  53. d1.pop_front();
  54. d2.pop_front();
  55. c2++;
  56. c1--;
  57. }else if(d1.front()>d2.front()){
  58. d1.push_back(d2.front());
  59. d1.push_back(d1.front());
  60. d2.pop_front();
  61. d1.pop_front();
  62. c1++;
  63. c2--;
  64. }
  65. counter++;
  66. if((d1==dd1&&d2==dd2)||counter==106){
  67. cout<<-1<<"\n";
  68. return;
  69. }
  70. }cout<<counter<<" ";
  71. if(d1.size()==0){
  72. cout<<2<<"\n";
  73. }else{
  74. cout<<1<<"\n";
  75. }
  76. }
  77.  
  78. int main(){
  79. Rofyda_Elghadban();
  80. solve();
  81.  
  82. return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement