Submission #538226

#TimeUsernameProblemLanguageResultExecution timeMemory
538226idasCutting a rectangle (LMIO18_staciakampis)C++11
0 / 100
1092 ms224676 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); } #define int long long const int N=1e5+10; int n, a[N], b[N]; vector<pii> inf; ll area; bool can(int x, int y) { if(x*y!=area) return false; map<int, stack<pii>> ar, br; FOR(i, 0, n) { ar[inf[i].f].push({inf[i].s, i}); br[inf[i].s].push({inf[i].f, i}); } map<int, bool> v; while(x>0 && y>0){ while(!ar[x].empty() && v[ar[x].top().s]) ar[x].pop(); while(!br[x].empty() && v[br[x].top().s]) br[x].pop(); while(!ar[y].empty() && v[ar[y].top().s]) ar[y].pop(); while(!br[y].empty() && v[br[y].top().s]) br[y].pop(); if(sz(ar[x])){ pii tp=ar[x].top(); v[tp.s]=true; y-=tp.f; ar[x].pop(); continue; } if(sz(ar[y])){ pii tp=ar[y].top(); v[tp.s]=true; x-=tp.f; ar[y].pop(); continue; } if(sz(br[x])){ pii tp=br[x].top(); v[tp.s]=true; y-=tp.f; br[x].pop(); continue; } if(sz(br[y])){ pii tp=br[y].top(); v[tp.s]=true; x-=tp.f; br[y].pop(); continue; } return false; } return true; } signed main() { setIO(); cin >> n; FOR(i, 0, n) { cin >> a[i] >> b[i]; inf.pb({a[i],b[i]}); area+=a[i]*b[i]; } set<int> ans; // FOR(i, 0, n) // { // FOR(j, i+1, n) // { // int x=a[i]+b[j], y=a[j]; // if(can(x, y)){ // ans.insert(min(x, y)); // } // // x=a[i]; y=b[i]+a[j]; // if(can(x, y)){ // ans.insert(min(x, y)); // } // } // } for(ll i=1; i*i<=area; i++){ if(area%i==0){ ll x=i, y=area/x; if(can(x, y)){ ans.insert(x); } } } cout << sz(ans) << '\n'; for(auto x : ans){ cout << x << '\n'; } }

Compilation message (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...