답안 #880963

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
880963 2023-11-30T09:19:29 Z abcvuitunggio 함박 스테이크 (JOI20_hamburg) C++17
2 / 100
69 ms 14056 KB
#include <bits/stdc++.h>
using namespace std;
const int INF=1e9;
int n,k,l[200001],d[200001],r[200001],u[200001],cnt[10],cnt2[10];
vector <pair <int, int>> res,v;
vector <int> a,b;
vector <int> f(vector <pair <int, int>> ve){
    vector <int> v;
    while (!ve.empty()){
        int mx=0;
        for (auto [l,r]:ve)
            mx=max(mx,l);
        v.push_back(mx);
        vector <pair <int, int>> tmp;
        for (auto [l,r]:ve)
            if (l>mx||r<mx)
                tmp.push_back({l,r});
        swap(ve,tmp);
    }
    return v;
}
void backtrack(int pos, int k){
    if (pos==a.size()*b.size()){
        int ch=1;
        for (int i=0;i<a.size();i++)
            if (!cnt[i])
                ch=0;
        for (int i=0;i<b.size();i++)
            if (!cnt2[i])
                ch=0;
        if (ch){
            for (int i=0;i<n;i++){
                int c=0;
                for (auto [x,y]:res)
                    if (l[i]<=x&&r[i]>=x&&d[i]<=y&&u[i]>=y){
                        c=1;
                        break;
                    }
                if (!c)
                    return;
            }
            for (auto [x,y]:res)
                cout << x << ' ' << y << '\n';
            while (k--)
                cout << 1 << ' ' << 1 << '\n';
            exit(0);
        }
        return;
    }
    int i=pos/b.size(),j=pos%b.size();
    backtrack(pos+1,k);
    if (k){
        cnt[i]++;
        cnt2[j]++;
        res.push_back({a[i],b[j]});
        backtrack(pos+1,k-1);
        cnt[i]--;
        cnt2[j]--;
        res.pop_back();
    }
}
int main(){
    ios_base::sync_with_stdio(NULL);cin.tie(nullptr);
    cin >> n >> k;
    for (int i=0;i<n;i++){
        cin >> l[i] >> d[i] >> r[i] >> u[i];
        v.push_back({l[i],r[i]});
    }
    a=f(v);
    v.clear();
    for (int i=0;i<n;i++)
        v.push_back({d[i],u[i]});
    b=f(v);
    backtrack(0,k);
}

Compilation message

hamburg.cpp: In function 'void backtrack(int, int)':
hamburg.cpp:23:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     if (pos==a.size()*b.size()){
      |         ~~~^~~~~~~~~~~~~~~~~~~
hamburg.cpp:25:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |         for (int i=0;i<a.size();i++)
      |                      ~^~~~~~~~~
hamburg.cpp:28:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |         for (int i=0;i<b.size();i++)
      |                      ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2652 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 2 ms 2652 KB Output is correct
5 Correct 2 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Incorrect 1 ms 2652 KB Unexpected end of file - int32 expected
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2528 KB Output is correct
3 Correct 1 ms 2648 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Incorrect 2 ms 2616 KB Unexpected end of file - int32 expected
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 68 ms 13964 KB Output is correct
6 Correct 67 ms 14056 KB Output is correct
7 Correct 69 ms 14012 KB Output is correct
8 Correct 68 ms 13928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2652 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 2 ms 2652 KB Output is correct
5 Correct 2 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Incorrect 1 ms 2652 KB Unexpected end of file - int32 expected
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2528 KB Output is correct
3 Correct 1 ms 2648 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Incorrect 2 ms 2616 KB Unexpected end of file - int32 expected
8 Halted 0 ms 0 KB -