Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <queue>
- #include <string>
- using namespace std;
- int main() {
- int n;
- cin >> n;
- queue<int> first, second;
- int cur;
- for (int i = 0; i < n / 2; ++i) {
- cin >> cur;
- first.push(cur);
- }
- for (int i = 0; i < n / 2; ++i) {
- cin >> cur;
- second.push(cur);
- }
- const int CNT_MOVES = 2e5;
- auto get_first = [&](int firstCard, int secondCard) {
- if (firstCard == 0 && secondCard == n - 1) return true;
- if (firstCard == n - 1 && secondCard == 0) return false;
- return firstCard > secondCard;
- };
- for (int i = 0; i < CNT_MOVES; ++i) {
- if (first.empty()) {
- cout << "second " << i << '\n';
- return 0;
- }
- if (second.empty()) {
- cout << "first " << i << '\n';
- return 0;
- }
- int firstCard = first.front();
- first.pop();
- int secondCard = second.front();
- second.pop();
- if (get_first(firstCard, secondCard)) {
- first.push(firstCard);
- first.push(secondCard);
- } else {
- second.push(firstCard);
- second.push(secondCard);
- }
- }
- cout << "draw";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement