Submission #502553


Source Code Expand

// {{{ include
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
// }}}

using namespace std;

typedef long long ll;
typedef pair<int, int> duo;
inline int in(){int x;scanf("%d",&x);return x;}
int N, K;

bool inBounds(int sx, int sy, int ex, int ey, const duo& p){
  return sx <= p.first && p.first <= ex && sy <= p.second && p.second <= ey;
}


void rect(const vector<duo>& P, int b, int& x, int& y, int& w, int& h){
  int min_x, min_y, max_x, max_y;
  min_x = min_y = N + 1;
  max_x = max_y = -1;

  for (int i = 0; i < K; i++){
    if ((b >> i) & 1) {
      const duo& p = P[i];
      min_x = min(min_x, p.first);
      min_y = min(min_y, p.second);
      max_x = max(max_x, p.first);
      max_y = max(max_y, p.second);
    }
  }
  x = min_x;
  y = min_y;
  w = max_x - min_x + 1;
  h = max_y - min_y + 1;
}


bool valid(const vector<duo>& P, int b, int x, int y, int w, int h){
  if (x <= 0 || y <= 0 || x + w - 1 > N || y + h - 1 > N) return false;
  for (int i = 0; i < K; i++){
    if ((b >> i) & 1) continue;
    if (inBounds(x, y, x + w - 1, y + h - 1, P[i])) return false;
  }
  return true;
}

int score(const vector<duo>& P, int b, int x, int y, int w, int h){
  if (!valid(P, b, x, y, w, h)) return -1;
  int red = 0;
  int blue = 0;
  if (w % 2 && h % 2) {
    if ((x + y) % 2) blue++;
    else red++;
  }
  for (int i = 0; i < K; i++){
    if (!((b >> i) & 1)) continue;
    const auto& p = P[i];
    if ((p.first + p.second) % 2) red += 2;
    else blue += 2;
  }
  return abs(red - blue);
}

int main()
{
  N = in(), K = in();
  vector<duo> P;
  for (int i = 0; i < K; i++){
    int y = in();
    int x = in();
    P.emplace_back(x, y);
  }

  int maxi = 1;
  for (int b = 1; b < (1 << K); b++){
    int x, y;
    int w, h;
    rect(P, b, x, y, w, h);
    maxi = max({
        score(P, b, x, y, w, h),
        score(P, b, x - 1, y, w + 1, h),
        score(P, b, x, y - 1, w, h + 1),
        score(P, b, x, y, w + 1, h),
        score(P, b, x, y, w, h + 1),
        score(P, b, x - 1, y - 1, w + 1, h + 1),
        score(P, b, x, y, w + 1, h + 1),
        score(P, b, x - 1, y, w + 1, h + 1),
        score(P, b, x, y - 1, w + 1, h + 1),
        maxi
    });
  }
  cout << maxi << endl;

  return 0;
}

Submission Info

Submission Time
Task E - マス目色ぬり
User tanishiOrisano
Language C++11 (GCC 4.9.2)
Score 0
Code Size 2452 Byte
Status WA
Exec Time 31 ms
Memory 928 KiB

Compile Error

./Main.cpp: In function ‘int in()’:
./Main.cpp:18:37: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
 inline int in(){int x;scanf("%d",&x);return x;}
                                     ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 100
Status
AC × 3
AC × 22
WA × 5
Set Name Test Cases
Sample example_0.txt, example_1.txt, example_2.txt
All all_black_0.txt, all_black_1.txt, all_edge_0.txt, all_edge_1.txt, all_edge_2.txt, all_white_0.txt, all_white_1.txt, corner_0.txt, example_0.txt, example_1.txt, example_2.txt, maxrand_0.txt, maxrand_1.txt, maxrand_2.txt, maxrand_3.txt, maxrand_4.txt, random_0.txt, random_1.txt, random_2.txt, random_3.txt, random_4.txt, smallrand_0.txt, smallrand_1.txt, smallrand_2.txt, example_0.txt, example_1.txt, example_2.txt
Case Name Status Exec Time Memory
all_black_0.txt AC 28 ms 924 KiB
all_black_1.txt AC 25 ms 928 KiB
all_edge_0.txt AC 24 ms 920 KiB
all_edge_1.txt AC 24 ms 924 KiB
all_edge_2.txt WA 28 ms 920 KiB
all_white_0.txt AC 25 ms 924 KiB
all_white_1.txt WA 31 ms 808 KiB
corner_0.txt AC 27 ms 928 KiB
example_0.txt AC 27 ms 804 KiB
example_1.txt AC 26 ms 924 KiB
example_2.txt AC 28 ms 912 KiB
maxrand_0.txt AC 27 ms 796 KiB
maxrand_1.txt AC 28 ms 920 KiB
maxrand_2.txt AC 28 ms 928 KiB
maxrand_3.txt AC 27 ms 920 KiB
maxrand_4.txt AC 28 ms 800 KiB
random_0.txt AC 29 ms 928 KiB
random_1.txt AC 28 ms 800 KiB
random_2.txt AC 27 ms 828 KiB
random_3.txt WA 26 ms 796 KiB
random_4.txt AC 29 ms 928 KiB
smallrand_0.txt WA 25 ms 924 KiB
smallrand_1.txt AC 26 ms 928 KiB
smallrand_2.txt WA 25 ms 924 KiB