Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define FOR(i,a,b) for (int i = (a); i < (b); i++)
- #define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
- #define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
- #define FILL(a,value) memset(a, value, sizeof(a))
- #define SZ(a) (int)a.size()
- #define ALL(a) a.begin(), a.end()
- #define PB push_back
- #define MP make_pair
- typedef long long LL;
- typedef vector<int> VI;
- typedef pair<int, int> PII;
- const double PI = acos(-1.0);
- const int INF = 1000 * 1000 * 1000 + 7;
- const LL LINF = INF * (LL) INF;
- const int MAX = 1010;
- vector<pair<int, PII> > P[MAX];
- void init()
- {
- FOR (i, 1, MAX+1)
- {
- FOR (j, i, MAX+1)
- {
- if (i * j > MAX) break;
- P[i*j].PB(MP(2*(i+j), MP(i, j)));
- }
- }
- P[0].PB(MP(0, MP(0, 0)));
- FOR (i, 0, MAX)
- {
- sort(ALL(P[i]));
- }
- }
- vector<PII> go(int s, int p, int ind)
- {
- if (s == 0 && p == 0) return vector<PII>();
- int mn = P[s][0].first;
- int mx = s * 4;
- // cout<<s<<' '<<p<<' '<<mn<<' '<<mx<<' '<<ind<<endl;
- if ((p & 1) || p < mn || p > mx)
- {
- cout<<"*"<<endl;
- vector<PII> r;
- r.PB(MP(-1, -1));
- return r;
- }
- vector<pair<int, PII> >& cur = P[s];
- /* cout<<"!!! ";
- FOR (i, 0, SZ(cur))
- {
- cout<<cur[i].first<<' ';
- }
- cout<<endl;*/
- RFOR(i, ind+1, 1)
- {
- int ns = s - i;
- if (ns < 0) continue;
- vector<pair<int, PII> >& v = P[ns];
- mn = v[0].first;
- mx = ns * 4;
- vector<pair<int, PII> >& cur = P[i];
- int val = p - mn;
- int pos = upper_bound(ALL(cur), MP(val, MP(INF, INF))) - cur.begin() - 1;
- // cout<<i<<' '<<val<<' '<<pos<<endl;
- if (pos >= 0)
- {
- int x = cur[pos].first;
- x = p - x;
- //cout<<cur[pos].first<<endl;
- //cout<<x<<endl;
- //cout<<mn<<' '<<mx<<endl;
- if (x >= mn && x <= mx)
- {
- vector<PII> res = go(ns, x, i);
- cout<<cur[pos].second.first<<' '<<cur[pos].second.second<<endl;
- res.PB(cur[pos].second);
- return res;
- }
- //cout<<"*"<<endl;
- }
- }
- throw -1;
- }
- int main()
- {
- //freopen("in.txt", "r", stdin);
- //ios::sync_with_stdio(false); cin.tie(0);
- init();
- FOR (i, 0, 10)
- {
- cout<<i<<": ";
- FOR (j, 0, SZ(P[i]))
- {
- cout<<P[i][j].first<<' ';
- }
- cout<<endl;
- }
- FOR (i, 1, 10)
- {
- FOR (j, 1, 40)
- {
- vector<PII> r = go(i, j, MAX);
- cout<<i<<' '<<j<<": ";
- FOR (k, 0, SZ(r))
- {
- cout<<r[k].first<<' '<<r[k].second<<", ";
- }
- cout<<endl;
- }
- }
- }
- 0: 0
- 1: 4
- 2: 6
- 3: 8
- 4: 8 10
- 5: 12
- 6: 10 14
- 7: 16
- 8: 12 18
- 9: 12 20
- 6 12
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement