Submission #537502

#TimeUsernameProblemLanguageResultExecution timeMemory
537502idasCutting a rectangle (LMIO18_staciakampis)C++11
0 / 100
1075 ms308 KiB
#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; vi ins; bool can(int tx, int ty, int vis) { 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) ins.pb(i); 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 (stderr)

staciakampis.cpp: In function 'bool can(int, int, int)':
staciakampis.cpp:67:17: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   67 |         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);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...