Advertisement
Derga

Untitled

Aug 22nd, 2023
608
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | None | 0 0
  1. #include <iostream>
  2. #include <queue>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     int n;
  9.     cin >> n;
  10.     queue<int> first, second;
  11.     int cur;
  12.     for (int i = 0; i < n / 2; ++i) {
  13.         cin >> cur;
  14.         first.push(cur);
  15.     }
  16.     for (int i = 0; i < n / 2; ++i) {
  17.         cin >> cur;
  18.         second.push(cur);
  19.     }
  20.     const int CNT_MOVES = 2e5;
  21.     auto get_first = [&](int firstCard, int secondCard) {
  22.         if (firstCard == 0 && secondCard == n - 1) return true;
  23.         if (firstCard == n - 1 && secondCard == 0) return false;
  24.         return firstCard > secondCard;
  25.     };
  26.     for (int i = 0; i < CNT_MOVES; ++i) {
  27.         if (first.empty()) {
  28.             cout << "second " << i << '\n';
  29.             return 0;
  30.         }
  31.         if (second.empty()) {
  32.             cout << "first " << i << '\n';
  33.             return 0;
  34.         }
  35.         int firstCard = first.front();
  36.         first.pop();
  37.         int secondCard = second.front();
  38.         second.pop();
  39.         if (get_first(firstCard, secondCard)) {
  40.             first.push(firstCard);
  41.             first.push(secondCard);
  42.         } else {
  43.             second.push(firstCard);
  44.             second.push(secondCard);
  45.         }
  46.     }
  47.     cout << "draw";
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement