답안 #243931

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
243931 2020-07-02T08:55:03 Z pavel Cutting a rectangle (LMIO18_staciakampis) C++14
0 / 100
5 ms 384 KB
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

const int MAXN = 100005;
const int INF = 1000000009;

int n;
ll a[MAXN], b[MAXN];
ll area = 0;

bool possible(int k, ll lw, ll lh){
    if(lw == 0 || lh == 0){
        return k == -1;
    }
    return a[k] == lw && b[k] <= lh && possible(k-1, lw, lh - b[k])
        || a[k] == lh && b[k] <= lw && possible(k-1, lw - b[k], lh)
        || b[k] == lw && a[k] <= lh && possible(k-1, lw, lh - a[k])
        || b[k] == lh && a[k] <= lw && possible(k-1, lw - a[k], lh);
}

int main(){
    scanf("%d", &n);
    for(int i=0;i<n;++i){
        scanf("%lld%lld", &a[i], &b[i]);
        area += a[i] * b[i];
    }
    vector<int> sol;
    if(area % a[n-1] == 0 && possible(n-1, a[n-1], area / a[n-1])){
        sol.push_back(min(a[n-1], area/a[n-1]));
    }
    if(area % b[n-1] == 0 && possible(n-1, b[n-1], area / b[n-1])){
        sol.push_back(min(b[n-1], area/b[n-1]));
    }
    sort(sol.begin(), sol.end());
    sol.erase(unique(sol.begin(), sol.end()), sol.end());
    printf("%d\n", sol.size());
    for(int i:sol){
        printf("%d\n", i);
    }
}

Compilation message

staciakampis.cpp: In function 'bool possible(int, ll, ll)':
staciakampis.cpp:20:37: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
     return a[k] == lw && b[k] <= lh && possible(k-1, lw, lh - b[k])
            ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
staciakampis.cpp:22:37: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
         || b[k] == lw && a[k] <= lh && possible(k-1, lw, lh - a[k])
            ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
staciakampis.cpp:23:37: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
         || b[k] == lh && a[k] <= lw && possible(k-1, lw - a[k], lh);
            ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
staciakampis.cpp: In function 'int main()':
staciakampis.cpp:41:30: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type {aka long unsigned int}' [-Wformat=]
     printf("%d\n", sol.size());
                    ~~~~~~~~~~^
staciakampis.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
staciakampis.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld%lld", &a[i], &b[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
2 Incorrect 4 ms 256 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
2 Incorrect 4 ms 256 KB Output isn't correct
3 Halted 0 ms 0 KB -