알고리즘/atcoder90제

앳코더90 - 033 - Not Too Bright(★2)

b1ackhand 2024. 12. 9. 15:34

https://atcoder.jp/contests/typical90/tasks/typical90_ag

 

H, W가 주어졌을 때, LED 켜진 개수를 최대화 하는 문제이다. 조건으로는 2*2 구간에 켜져있는 LED가 1개만 있게 키는것이다. 조금 생각해봤을 때, 그리디한 접근으로 2*2에 불이 켜져있게 하려면 왼쪽 위부터 차근차근 불을 키면된다. 수식으로 정리하면 (H+1)/2 * (W+1)/2 이다. 

 

이렇게 제출하니 틀렸다고 나오자 corner케이스가 있나 하고 검토를 해봤지만 찾을 수 없어서 몇개의 테캐나 통과를 못했는지 보러갔는데, corner1~10.txt 정도의 케이스를 통과를 못했다. 그래서, 설마 1칸짜리면 LED가 빼곡히 들어가도 되나? 싶었다. 조건이 2*2구간 안에 켜져야 하기 때문에 1칸은 무시해도 되지 않을까 싶었다.

 

그리고 그 생각이 맞았다. 똥문제이다.

 

#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_set>
#include <numeric>
#include <random>
#include <iostream>
#include <unordered_map>
#include <atcoder/all>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define range(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back

using namespace std;
using namespace atcoder;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vll;

const int INF = 2000000000;
const double pi = 3.14159265358979;
const int MOD = 100000;

void yesno(bool a)
{
	if (a)
		cout << "YES\n";
	else
		cout << "NO\n";
}


int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int H, W;

	cin >> H >> W;

	if (H == 1 || W == 1)
		cout << H * W;
	else
		cout << ((H + 1) / 2) * ((W + 1) / 2);

	return 0;
}