Advertisement
willy108

gcj B but bad impl

Apr 8th, 2022
1,135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.02 KB | None | 0 0
  1.  
  2. ll sum(const vector<ll>& a){
  3.     ll ans = 0;
  4.     for(ll x : a) ans += x;
  5.     return ans;
  6. }
  7. void solve(){
  8.     int n;
  9.     cin >> n;
  10.     assert( n == 100);
  11.     //ternary?
  12.     vector<ll> oup;
  13.     ll p3 = 1;
  14.     for( p3 = 1; p3<=1e9; p3*=3ll){
  15.         oup.pb(p3);
  16.         oup.pb(p3*2);
  17.     }
  18.     oup.pb(p3/2);
  19.     oup.pb(p3/2 +1);
  20.     int aux = 100 - sz(oup);
  21.     //cout << aux << "\n";
  22.     for(int i = 0; i<aux; i++){
  23.         oup.pb(1e9 -i);
  24.     }
  25.     sort(all(oup));
  26.     oup.resize(unique(all(oup)) - oup.begin());
  27.     assert(sz(oup) == 100);
  28.     //for(ll x : oup) cout << x << " " ;
  29.     //cout << endl;
  30.  
  31.     for(ll x : oup){
  32.         assert(1 <= x && x <= 1e9);
  33.         cout << x << " " ;
  34.     }
  35.     cout << endl;
  36.     vector<ll> inp(n);
  37.     int cnt = 1e9 -100;
  38.     for(ll& x : inp){
  39.         //cnt++;
  40.         cin >> x;
  41.         //x = cnt;
  42.     }
  43.     sort(all(inp));
  44.     vector<ll> ans1, ans2;
  45.     ll tot1 = 0, tot2 = 0;
  46.     for(int i = 0; i<n; i+=2){
  47.         tot1 += inp[i];
  48.         tot2 += inp[i+1];
  49.         ans1.pb(inp[i]);
  50.         ans2.pb(inp[i+1]);
  51.     }
  52.     assert(tot2 >= tot1);
  53.     ll diff = tot2 - tot1;
  54.     for(ll p = 1; p<=1e9; p *= 3ll){
  55.         ll dig = diff/p %3ll;
  56.         if(dig == 0){
  57.             ans2.pb(p);
  58.             ans2.pb(p*2ll);
  59.             diff += p*3ll;
  60.         }else if(dig == 2){
  61.             ans1.pb(p);
  62.             ans2.pb(p*2ll);
  63.             diff += p;
  64.         }else{
  65.             ans2.pb(p);
  66.             ans1.pb(p*2);
  67.             //diff += p*2ll;
  68.         }
  69.     }
  70.     if(diff/p3 %3ll == 1){
  71.         ans1.pb(p3/2);
  72.         ans1.pb(p3/2 +1);
  73.         //ans1.pb(1);
  74.     }else{
  75.         assert(0);
  76.     }  
  77.     for(int i = 0; i<aux/4; i++){
  78.         ans1.pb(1e9 - i);
  79.         ans1.pb(1e9 - aux + (i+1));
  80.         ans2.pb(1e9 - aux/2 - i);
  81.         ans2.pb(1e9 - aux/2 +(i+1));
  82.     }
  83.     vector<ll> fa = ans1;
  84.     for(ll x : ans2) fa.pb(x);
  85.     sort(all(fa));
  86.     vector<ll> sa = inp;
  87.     for(ll x : oup) sa.pb(x);
  88.     sort(all(sa));
  89.     assert(fa == sa);
  90.     //for(int i = 0; i<sz(fa); i++){
  91.         //cerr << fa[i] << " " << sa[i] << endl;
  92.     //}
  93.     assert(sum(ans1) == sum(ans2));
  94.     //cerr << sum(ans1) << " " << (ll)sum(ans2) << "\n";
  95.     //cerr << (ll)(sum(ans1) - sum(ans2)) << "\n";
  96.     //cerr << p3 << "\n";
  97.  
  98.    
  99.  
  100.     for(ll x : ans1){
  101.         assert(binary_search(all(oup), x) || binary_search(all(inp), x));
  102.         cout << x << " ";
  103.     }
  104.     cout << endl;
  105. }
  106.  
  107.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement