Code Submission Evaluation System Login

CSES - HIIT Open 2018

HIIT Open 2018

Contest start:2018-05-26 11:00:00
Contest end:2018-05-26 16:00:00

Task list | Submit code | Submissions | Messages | Scoreboard | Statistics


History
2018-05-26 14:42:58
2018-05-26 14:31:19
Task:Coins
Sender:DualCore
Submission time:2018-05-26 14:42:58
Status:READY
Result:WRONG ANSWER

Show test data

Code

#include <iostream>
#include <string>
#include <vector>
#include <set>

int main()
{
  std::string first_line;
  int n;
  std::getline(std::cin, first_line);
  n = std::stoi(first_line);
  std::set<int> left, right;
  int previous = 0;
  for (int i = 0; i < n; ++i)
    {
      std::string line;
      std::getline(std::cin, line);
      std::size_t pos;
      int c = std::stoi(line, &pos);
      int s = std::stoi(line.substr(pos, line.length() - pos));

      (s == 1) ? left.insert(c) : right.insert(c);

      if (s == previous)
	{
	  s == 1 ? std::cout << ">\n" : std::cout << "<\n";
	  continue;
	}

      bool left_are_greater = true;
      bool right_are_greater = true;

      if (left.size() == 0)
	{
	  std::cout << "<\n";
	  previous = 2;
	  continue;
	}
      if (right.size() == 0)
	{
	  std::cout << ">\n";
	  previous = 1;
	  continue;
	}
      
      if (left.size() == right.size())
	{
	  for (auto leftit = left.rbegin(), rightit = right.rbegin(); leftit != left.rend(); ++leftit, ++rightit)
	    {
	      if (*leftit > *rightit)
		right_are_greater = false;
	      else
		left_are_greater = false;
	      if (!(left_are_greater || right_are_greater))
		break;
	    }
	  if (left_are_greater)
	    {
	      previous = 1;
	      std::cout << ">\n";
	    }
	  else if (right_are_greater)
	    {
	      previous = 2;
	      std::cout << "<\n";
	    }
	  else
	    {
	      previous = 0;
	      std::cout << "?\n";
	    }
	}
      else if (left.size() > right.size())
	{
	  for (auto leftit = left.rbegin(), rightit = right.rbegin(); rightit != right.rend(); ++leftit, ++rightit)
	    {
	      if (*leftit > *rightit)
		right_are_greater = false;
	      else
		left_are_greater = false;
	      if (!(left_are_greater || right_are_greater))
		break;
	    }
	  if (right_are_greater)
	    {
	      previous = 0;
	      std::cout << "?\n";
	    }
	  else
	    {
	      previous = 1;
	      std::cout << ">\n";
	    }
	}
      else
	{
	  for (auto leftit = left.rbegin(), rightit = right.rbegin(); leftit != left.rend(); ++leftit, ++rightit)
	    {
	      if (*leftit > *rightit)
		right_are_greater = false;
	      else
		left_are_greater = false;
	      if (!(left_are_greater || right_are_greater))
		break;
	    }
	  if (left_are_greater)
	    {
	      previous = 0;
	      std::cout << "?\n";
	    }
	  else
	    {
	      previous = 2;
	      std::cout << "<\n";
	    }
	}
      
    }

}