답안 #537490

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
537490 2022-03-15T07:17:04 Z idas Cutting a rectangle (LMIO18_staciakampis) C++11
0 / 100
1 ms 340 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 x, int y, int vis)
{
    FOR(i, 1, n)
    {
        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{
            return false;
        }
    }
    if((x==0 && y>0) || (y==0 && x>0))
        return true;
    else
        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]));
        }
//        if(i==2){
//            cout << x << " " << y << endl;
//            FOR(j, 1, n)
//            {
//                if(i==j) continue;
//                cout << a[j] << " " << b[j] << endl;
//            }
//            cout << endl;
//        }

        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 '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 1 ms 340 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -