답안 #537496

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
537496 2022-03-15T07:25:37 Z idas Cutting a rectangle (LMIO18_staciakampis) C++11
0 / 100
1000 ms 212 KB
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i = (begin); i < (end); i++)
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr)
#define f first
#define s second
#define pb push_back
#define sz(x) ((int)((x).size()))
#define le(vec) vec[vec.size()-1]
#define all(x) (x).begin(), (x).end()
#define TSTS int ttt; cin >> ttt; while(ttt--) solve()

using namespace std;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long double, long double> pdd;
typedef map<int, int> mii;
typedef vector<int> vi;
typedef long double ld;
typedef long long ll;

const int INF=1e9, MOD=1e9+7, mod=998244353;
const ll LINF=1e18;

void setIO()
{
    FAST_IO;
}

void setIO(string s)
{
    FAST_IO;
    freopen((s+".in").c_str(), "r", stdin);
    freopen((s+".out").c_str(), "w", stdout);
}

const int N=1e5+10;
int n, a[N], b[N];
vector<pii> inf;
set<int> ans;

bool can(int tx, int ty, int vis)
{
    vi ins;
    FOR(i, 0, n) ins.pb(i);

    do{
        bool bad=false;
        int x=tx, y=ty;
        for(auto i : ins){
            if(i==0) continue;
            if(i==vis) continue;
            if(a[i]==x){
                y-=b[i];
            }
            else if(a[i]==y){
                x-=b[i];
            }
            else if(b[i]==x){
                y-=a[i];
            }
            else if(b[i]==y){
                x-=a[i];
            }
            else{
                bad=true;
            }
        }
        if(!bad && (x==0 && y>0) || (y==0 && x>0)){
            return true;
        }
    }
    while(next_permutation(all(ins)));
    return false;
}

int main()
{
    setIO();
    cin >> n;
    FOR(i, 0, n)
    {
        int aa, bb;
        cin >> aa >> bb;
        inf.pb({aa,bb});
    }
    sort(all(inf), greater<pii>());
    FOR(i, 0, n)
    {
        a[i]=inf[i].f; b[i]=inf[i].s;
    }

    FOR(i, 1, n)
    {
        int x=a[i], y=a[0]-b[i];
        if(can(x, y, i)){
            ans.insert(min(a[i]+b[0], a[0]));
        }

        x=a[0]; y=a[i]-b[0];
        if(can(x, y, i)){
            ans.insert(min(a[i], a[0]+b[i]));
        }
        x=a[0]-a[i]; y=b[i];
        if(can(x, y, i)){
            ans.insert(min(a[0], b[0]+b[i]));
        }
    }

    bool ok=true;
    int sm=b[0];
    FOR(i, 1, n)
    {
        if(a[i]!=sm && b[i]!=sm){
            ok=false;
            break;
        }
    }
    if(ok) ans.insert(sm);

    cout << sz(ans) << "\n";
    for(auto x : ans){
        cout << x << "\n";
    }
}

Compilation message

staciakampis.cpp: In function 'bool can(int, int, int)':
staciakampis.cpp:68:17: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   68 |         if(!bad && (x==0 && y>0) || (y==0 && x>0)){
      |            ~~~~~^~~~~~~~~~~~~~~~
staciakampis.cpp: In function 'void setIO(std::string)':
staciakampis.cpp:32:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |     freopen((s+".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
staciakampis.cpp:33:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     freopen((s+".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 253 ms 212 KB Output is correct
4 Execution timed out 1085 ms 212 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1084 ms 212 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 253 ms 212 KB Output is correct
4 Execution timed out 1085 ms 212 KB Time limit exceeded
5 Halted 0 ms 0 KB -