답안 #245162

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
245162 2020-07-05T16:07:53 Z urd05 매트 (KOI15_mat) C++14
21 / 100
14 ms 384 KB
#include <bits/stdc++.h>
using namespace std;

struct Mat {
    int p,l,r,h,k;
};

Mat arr[10];
bool meet[10][10];
int n,w;

bool isMeet(Mat a,Mat b) {
    if (a.p==b.p) {
        if (a.r<=b.l||b.r<=a.l) {
            return false;
        }
        return true;
    }
    else {
        if (a.h+b.h<=w) {
            return false;
        }
        if (a.r<=b.l||b.r<=a.l) {
            return false;
        }
        return true;
    }
}

int main(void) {
    scanf("%d %d",&n,&w);
    for(int i=0;i<n;i++) {
        scanf("%d %d %d %d %d",&arr[i].p,&arr[i].l,&arr[i].r,&arr[i].h,&arr[i].k);
    }
    long long ret=0;
    for(int i=0;i<n;i++) {
        for(int j=0;j<n;j++) {
            if (isMeet(arr[i],arr[j])) {
                meet[i][j]=true;
            }
        }
    }
    for(int i=0;i<(1<<n);i++) {
        bool flag=true;
        for(int one=0;one<n;one++) {
            for(int two=0;two<n;two++) {
                if (one!=two&&(i&(1<<one))!=0&&(i&(1<<two))!=0) {
                    if (meet[one][two]) {
                        flag=false;
                        break;
                    }
                }
            }
        }
        if (!flag) {
            continue;
        }
        long long sum=0;
        for(int j=0;j<n;j++) {
            if ((i&(1<<j))!=0) {
                sum+=arr[j].k;
            }
        }
        ret=max(ret,sum);
    }
    printf("%lld",ret);
}

Compilation message

mat.cpp: In function 'int main()':
mat.cpp:31:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d",&n,&w);
     ~~~~~^~~~~~~~~~~~~~~
mat.cpp:33:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %d %d %d",&arr[i].p,&arr[i].l,&arr[i].r,&arr[i].h,&arr[i].k);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 14 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6 ms 384 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5 ms 384 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -