Help us understand the problem. What is going on with this article?


More than 5 years have passed since last update.


#include <boost/test/included/unit_test.hpp>

using namespace std;
using namespace boost;
typedef pair<size_t, size_t> pair_t;

vector<pair_t> get_rect(const string& s){
    vector<pair_t> v;
    for(size_t i=0; i<s.length(); i+=3){
        if(s[i] == '-'){
    return v;

void set_pos(set<string>& s, pair_t x, pair_t y){
    for(size_t j=y.first; j<=y.second; ++j){
        for(size_t i=x.first; i<=x.second; ++i){
            s.insert(lexical_cast<string>(i) + lexical_cast<string>(j));

bool same(const set<string>& red, const string& green){
    set<string>::iterator found = find(red.begin(), red.end(), green);
    return found != red.end();

size_t solve(const string& s){
    vector<pair_t> pos = get_rect(s);
    set<string> red, green;
    for(size_t i=1; i<3; ++i){
        set_pos(red, pair_t(min(pos[0].first, pos[i].first), max(pos[0].first, pos[i].first)), pair_t(min(pos[0].second, pos[i].second), max(pos[0].second, pos[i].second)));
        set_pos(green, pair_t(min(pos[3].first, pos[i+3].first), max(pos[3].first, pos[i+3].first)), pair_t(min(pos[3].second, pos[i+3].second), max(pos[3].second, pos[i+3].second)));
    return count_if(green.begin(), green.end(), bind(&same, red, _1));

BOOST_AUTO_TEST_CASE( solve_test1 ){
    BOOST_CHECK_EQUAL(solve("23-94-28,89-06-51"), 11);

BOOST_AUTO_TEST_CASE( solve_test2 ){
    BOOST_CHECK_EQUAL(solve("11-84-58,02-73-69"), 40);

BOOST_AUTO_TEST_CASE( solve_test3 ){
    BOOST_CHECK_EQUAL(solve("18-41-86,77-04-32"), 26);

BOOST_AUTO_TEST_CASE( solve_test4 ){
    BOOST_CHECK_EQUAL(solve("81-88-23,64-58-14"), 0);

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away