Implementation
We can brute force all rotations of the three rectangles with a bitmask of , with bit representing whether the 'th rectangle should be rotated by degrees. The rest is just checking if the configurations are valid.
Time Complexity: , where is the number of rectangles (in this case, 3) and as the side length of the square.
C++
#include <bits/stdc++.h>using namespace std;const int N = 3;int main() {vector<pair<int, int>> logos(N);for (int i = 0; i < N; i++) { scanf("%d%d", &logos[i].first, &logos[i].second); }long long area = 0;for (pair<int, int> p : logos) { area += p.first * p.second; }
Java
import java.util.*;public class ThreeLogos {private static final int N = 3;public static void main(String[] args) {Scanner scanner = new Scanner(System.in);int[][] logos = new int[N][2];for (int i = 0; i < N; i++) {logos[i][0] = scanner.nextInt();
Python
def main():import sysdata = sys.stdin.read().split()N = 3logos = [(int(data[i * 2]), int(data[i * 2 + 1])) for i in range(N)]area = sum(p[0] * p[1] for p in logos)
Alternative Implementation
This problem can be solved in time (ignoring the time to print the output), by simply considering the two possible cases.
If the logos can fit they can either:
- be placed one under the other, similar to the first sample
- or one can be placed on top and the other two will be placed next to each other.
C++
#include <bits/stdc++.h>using namespace std;struct point {int x, y;char ch;void print(void) {for (int i = 0; i < this->y; i++) {for (int j = 0; j < this->x; j++) cout << this->ch;
Python
class Logo:def __init__(self, x, y, ch):# Rotate logos to reduce the amount of casework# Longer side = x, shorter side = yif x < y:y, x = x, yself.x = xself.y = yself.ch = ch
Join the USACO Forum!
Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!