Submission #880787

# Submission time Handle Problem Language Result Execution time Memory
880787 2023-11-30T04:05:37 Z abcvuitunggio Hamburg Steak (JOI20_hamburg) C++17
6 / 100
76 ms 5972 KB
#include <bits/stdc++.h>
using namespace std;
const int INF=1e9;
int n,k,l[200001],d[200001],r[200001],u[200001];
vector <pair <int, int>> res;
vector <int> v;
bool check(int l, int r, int x){
    return (x>=l&&x<=r);
}
bool solve(vector <int> v, int k){
    if (v.empty()){
        while (k--)
            res.push_back({1,1});
        return true;
    }
    if (!k)
        return false;
    vector <int> a,b;
    int sz=max(k,2);
    int mn[sz],mx[sz],mn2[sz],mx2[sz];
    for (int i=0;i<sz;i++){
        mn[i]=mn2[i]=INF;
        mx[i]=mx2[i]=0;
    }
    for (int i:v){
        mx[sz-1]=l[i];
        mn[sz-1]=r[i];
        mx2[sz-1]=d[i];
        mn2[sz-1]=u[i];
        for (int i=sz-2;i>=0;i--){
            if (mx[i]<mx[i+1])
                swap(mx[i],mx[i+1]);
            if (mn[i]>mn[i+1])
                swap(mn[i],mn[i+1]);
            if (mx2[i]<mx2[i+1])
                swap(mx2[i],mx2[i+1]);
            if (mn2[i]>mn2[i+1])
                swap(mn2[i],mn2[i+1]);
        }
    }
    for (int i=0;i<sz-1;i++){
        a.push_back(mn[i]);
        b.push_back(mn2[i]);
    }
    for (int i=0;i<sz-1;i++){
        if (mx[i]>a.back())
            a.push_back(mx[i]);
        if (mx2[i]>b.back())
            b.push_back(mx2[i]);
    }
    if (a.size()==1&&b.size()==1){
        while (k--)
            res.push_back({a[0],b[0]});
        return true;
    }
    if (k==1)
        return false;
    vector <pair <int, int>> c;
    for (int i:a)
        for (int j:b)
            c.push_back({i,j});
    for (int i=0;i<c.size();i++)
        for (int j=i+1;j<c.size();j++){
            vector <int> v2;
            for (int k:v){
                if ((!check(l[k],r[k],c[i].first)||!check(d[k],u[k],c[i].second))&&(!check(l[k],r[k],c[j].first)||!check(d[k],u[k],c[j].second)))
                    v2.push_back(k);
            }
            if (solve(v2,k-2)){
                res.push_back(c[i]);
                res.push_back(c[j]);
                return true;
            }
        }
    return false;
}
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(i);
    }
    bool tmp=solve(v,k);
    for (auto [x,y]:res)
        cout << x << ' ' << y << '\n';
}

Compilation message

hamburg.cpp: In function 'bool solve(std::vector<int>, int)':
hamburg.cpp:62:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     for (int i=0;i<c.size();i++)
      |                  ~^~~~~~~~~
hamburg.cpp:63:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |         for (int j=i+1;j<c.size();j++){
      |                        ~^~~~~~~~~
hamburg.cpp: In function 'int main()':
hamburg.cpp:84:10: warning: unused variable 'tmp' [-Wunused-variable]
   84 |     bool tmp=solve(v,k);
      |          ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 2 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Incorrect 2 ms 2396 KB Unexpected end of file - int32 expected
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 2 ms 2396 KB Output is correct
7 Correct 3 ms 2392 KB Output is correct
8 Incorrect 10 ms 2392 KB Unexpected end of file - int32 expected
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 61 ms 5072 KB Output is correct
6 Correct 63 ms 5068 KB Output is correct
7 Correct 68 ms 5036 KB Output is correct
8 Correct 60 ms 5184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 2 ms 2392 KB Output is correct
5 Correct 76 ms 5580 KB Output is correct
6 Correct 67 ms 5324 KB Output is correct
7 Correct 69 ms 5840 KB Output is correct
8 Correct 69 ms 5972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Incorrect 2 ms 2396 KB Unexpected end of file - int32 expected
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 2 ms 2396 KB Output is correct
7 Correct 3 ms 2392 KB Output is correct
8 Incorrect 10 ms 2392 KB Unexpected end of file - int32 expected
9 Halted 0 ms 0 KB -