제출 #538214

#제출 시각아이디문제언어결과실행 시간메모리
538214idasCutting a rectangle (LMIO18_staciakampis)C++11
0 / 100
23 ms4220 KiB
#include <bits/stdc++.h> #define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr) #define FOR(i, begin, end) for(int i = (begin); i < (end); i++) #define TSTS int ttt; cin >> ttt; while(ttt--) solve() #define all(x) (x).begin(), (x).end() #define le(vec) vec[vec.size()-1] #define sz(x) ((int)((x).size())) #define pb push_back #define s second #define f first using namespace std; typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef map<int, int> mii; typedef pair<int, int> pii; typedef pair<long long, long long> pll; typedef pair<long double, long double> pdd; const int INF=1e9, MOD=1e9+7, mod=998244353; const ll LINF=1e13; 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, M=5e6+10; int n, a[N], b[N]; vector<pii> inf, sa, sb; bool v[M]; 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{ // return false; // } // } // return true; map<int, set<int>> ar, br; FOR(i, 1, n) { if(i==vis) continue; ar[sa[i].f].insert(sa[i].s); br[sb[i].f].insert(sb[i].s); } function<pii(int)> eg_a=[&](int x){ if(sz(ar[x])){ int rt=*ar[x].begin(); ar[x].erase(ar[x].begin()); return pii({x,rt}); } else return pii({-1,-1}); }; function<pii(int)> eg_b=[&](int x){ if(sz(br[x])){ int rt=*br[x].begin(); br[x].erase(br[x].begin()); return pii({x,rt}); } else return pii({-1,-1}); }; int usd=0; while(true){ if(x<y) swap(x, y); pii now=eg_a(x); if(now.f!=-1 && now.s<=y){ y-=now.s; usd++; continue; } now=eg_b(x); if(now.f!=-1 && now.s<=y){ y-=now.s; usd++; continue; } now=eg_a(y); if(now.f!=-1 && now.s<=x){ x-=now.s; usd++; continue; } now=eg_b(y); if(now.f!=-1 && now.s<=x){ x-=now.s; usd++; continue; } break; } if(usd==n-2){ return true; } else{ return false; } } int main() { setIO(); cin >> n; ll area=0; FOR(i, 0, n) { cin >> a[i] >> b[i]; area+=a[i]*b[i]; inf.pb({a[i],b[i]}); } sort(all(inf), greater<pii>()); FOR(i, 0, n) a[i]=inf[i].f, b[i]=inf[i].s; FOR(i, 0, n) { sa.pb(inf[i]); sb.pb({inf[i].s, inf[i].f}); } //sort(all(sa)); sort(all(sb)); set<int> ans; FOR(i, 1, n) { int x=a[i], y=a[0]-b[i]; if((a[i]+b[0])*(a[0])==area){ if(can(x, y, i)){ ans.insert(min(a[i]+b[0], a[0])); } } x=a[i]-b[0]; y=a[0]; if((a[i])*(a[0]+b[i])==area){ if(can(x, y, i)){ ans.insert(min(a[i], a[0]+b[i])); } } } FOR(i, 1, n) { if(v[b[i]]) continue; v[b[i]]=true; int x=b[i]-b[0], y=a[0]; if((b[i])*(a[0]+a[i])==area){ if(can(x, y, i)){ ans.insert(b[i]); } } x=b[i]; y=a[0]-a[i]; if((b[i]+b[0])*a[0]==area){ if(can(x, y, i)){ ans.insert(min(b[i]+b[0], a[0])); } } } int cur=b[0]; bool bad=false; FOR(i, 1, n) { if(a[i]!=cur && b[i]!=cur){ bad=true; } } if(!bad){ ans.insert(cur); } cout << sz(ans) << "\n"; for(auto x : ans){ cout << x << "\n"; } }

컴파일 시 표준 에러 (stderr) 메시지

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);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...