Advertisement
aayyk

Untitled

Oct 29th, 2019
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.17 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cstdlib>
  4. #include <algorithm>
  5. #include <vector>
  6. #include <queue>
  7. #include <stack>
  8. #include <climits>
  9. #include <string>
  10. #include <set>
  11. #include <cmath>
  12. #include <map>
  13. #include <unordered_map>
  14. #include <numeric>
  15. #include <random>
  16. #include <memory>
  17. #include <chrono>
  18. #include <iterator>
  19. #include <functional>
  20. #include <unordered_set>
  21. #include <cassert>
  22. #ifdef LOCAL
  23. #include "debug.h"
  24. #else
  25. #define debug(x...)
  26. #endif
  27. //#pragma GCC optimize("Ofast")
  28. //#define int ll
  29.  
  30.  
  31.  
  32. using namespace std;
  33. typedef long long ll;
  34. typedef long double ld;
  35. typedef pair <int, int> pii;
  36. #define mp make_pair
  37. #define pb push_back
  38. #define sz(x) int((x).size())
  39.  
  40. #ifndef LOCAL
  41. mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  42. #else
  43. mt19937 rng(228);
  44. #endif
  45.  
  46. const int N = 1e6 + 7;
  47. const int inf = INT_MAX / 2;
  48. const ll INF = LLONG_MAX / 3;
  49. const int MOD = 1e9 + 7;
  50. const ld eps = 1e-6;
  51. const string cars[] = {"🚗", "🚕", "🚙"};
  52.  
  53. struct mask {
  54.     private: vector < int8_t > v;
  55.     private: bool space = true;
  56.  
  57.  
  58.     public: mask() {}
  59.     public: mask(int len) : v(vector < int8_t > (len)) {}
  60.  
  61.     public: const mask& operator++ () {
  62.         int i;
  63.         for (i = sz(v) - 1; i >= 0; i--) {
  64.             if (v[i] == 2) {
  65.                 v[i] = 0;
  66.             }
  67.             else {
  68.                 v[i]++;
  69.                 break;
  70.             }
  71.         }
  72.  
  73.         space = (i >= 0);
  74.         return *this;
  75.     }
  76.  
  77.     public: operator bool() const {
  78.         return space;
  79.     }
  80.  
  81.     public: int8_t operator[] (int x) {
  82.         return v[x];
  83.     }
  84.  
  85.     public: int size() {
  86.         return v.size();
  87.     }
  88. };
  89.  
  90. inline int mod(int x, int m) {
  91.     return x % m;
  92. }
  93.  
  94. void print(mask& u, mask& v) {
  95.     vector < int > ansl, ansr;
  96.     for (int i = 0; i < sz(u); i++) {
  97.         if (u[i] == 1) {
  98.             ansl.pb(i + 1);
  99.         }
  100.         if (u[i] == 2) {
  101.             ansr.pb(i + 1);
  102.         }
  103.     }
  104.  
  105.     for (int i = 0; i < sz(v); i++) {
  106.         if (v[i] == 1) {
  107.             ansl.pb(sz(u) + i + 1);
  108.         }
  109.         if (v[i] == 2) {
  110.             ansr.pb(sz(u) + i + 1);
  111.         }
  112.     }
  113.  
  114.     if (sz(ansl) + sz(ansr) > 0) {
  115.         cout << sz(ansl) << endl;
  116.         for (int x : ansl) {
  117.             cout << x << " ";
  118.         }
  119.         cout << endl << sz(ansr) << endl;
  120.         for (int x : ansr) {
  121.             cout << x << " ";
  122.         }
  123.  
  124.         exit(0);
  125.     }
  126. }
  127.  
  128. signed main() {
  129. #ifdef LOCAL
  130.     freopen("input.txt", "r", stdin);
  131.     freopen("output.txt", "w", stdout);
  132. #endif
  133.     cout << fixed << setprecision(9);
  134.     ios::sync_with_stdio(false);
  135.     cin.tie();
  136.     cout.tie();
  137.  
  138.     int n, m;
  139.     cin >> n >> m;
  140.     vector < int > a(n);
  141.  
  142.     for (int& x : a) {
  143.         cin >> x;
  144.     }
  145.  
  146.     vector < pair < int, mask > > l, r;
  147.  
  148.     for (mask mm(n / 2); mm; ++mm) {
  149.         int sum = 0;
  150.         for (int i = 0; i < n / 2; i++) {
  151.             if (mm[i] == 1) {
  152.                 sum = mod(sum + a[i], m);
  153.             }
  154.             if (mm[i] == 2) {
  155.                 sum = mod(sum - a[i], m);
  156.             }
  157.         }
  158.  
  159.         l.pb({ sum, mm });
  160.     }
  161.  
  162.     for (mask mm(n / 2 + n % 2); mm; ++mm) {
  163.         int sum = 0;
  164.         for (int i = n / 2, j = 0; i < n; i++, j++) {
  165.             if (mm[j] == 1) {
  166.                 sum = mod(sum + a[i], m);
  167.             }
  168.             if (mm[j] == 2) {
  169.                 sum = mod(sum - a[i], m);
  170.             }
  171.         }
  172.         r.pb({ sum, mm });
  173.     }
  174.  
  175.     sort(l.begin(), l.end());
  176.     sort(r.begin(), r.end());
  177.  
  178.     for (auto& [x, mm] : l) {
  179.         auto ptr = lower_bound(r.begin(), r.end(), mp(-x, mask()));
  180.         if (ptr->first == -x) {
  181.             print(mm, ptr->second);
  182.             if (ptr != r.end() && (ptr + 1)->first == -x) {
  183.                 print(mm, (ptr + 1)->second);
  184.             }
  185.         }
  186.  
  187.         ptr = lower_bound(r.begin(), r.end(), mp(m - x, mask()));
  188.         if (ptr->first == m - x) {
  189.             print(mm, ptr->second);
  190.             if (ptr != r.end() && (ptr + 1)->first == m - x) {
  191.                 print(mm, ptr->second);
  192.             }
  193.         }
  194.     }
  195.  
  196.     cout << -1;
  197.  
  198.     return 0;
  199. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement