Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <cstdlib>
- #include <algorithm>
- #include <vector>
- #include <queue>
- #include <stack>
- #include <climits>
- #include <string>
- #include <set>
- #include <cmath>
- #include <map>
- #include <unordered_map>
- #include <numeric>
- #include <random>
- #include <memory>
- #include <chrono>
- #include <iterator>
- #include <functional>
- #include <unordered_set>
- #include <cassert>
- #ifdef LOCAL
- #include "debug.h"
- #else
- #define debug(x...)
- #endif
- //#pragma GCC optimize("Ofast")
- //#define int ll
- using namespace std;
- typedef long long ll;
- typedef long double ld;
- typedef pair <int, int> pii;
- #define mp make_pair
- #define pb push_back
- #define sz(x) int((x).size())
- #ifndef LOCAL
- mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
- #else
- mt19937 rng(228);
- #endif
- const int N = 1e6 + 7;
- const int inf = INT_MAX / 2;
- const ll INF = LLONG_MAX / 3;
- const int MOD = 1e9 + 7;
- const ld eps = 1e-6;
- const string cars[] = {"🚗", "🚕", "🚙"};
- struct mask {
- private: vector < int8_t > v;
- private: bool space = true;
- public: mask() {}
- public: mask(int len) : v(vector < int8_t > (len)) {}
- public: const mask& operator++ () {
- int i;
- for (i = sz(v) - 1; i >= 0; i--) {
- if (v[i] == 2) {
- v[i] = 0;
- }
- else {
- v[i]++;
- break;
- }
- }
- space = (i >= 0);
- return *this;
- }
- public: operator bool() const {
- return space;
- }
- public: int8_t operator[] (int x) {
- return v[x];
- }
- public: int size() {
- return v.size();
- }
- };
- inline int mod(int x, int m) {
- return x % m;
- }
- void print(mask& u, mask& v) {
- vector < int > ansl, ansr;
- for (int i = 0; i < sz(u); i++) {
- if (u[i] == 1) {
- ansl.pb(i + 1);
- }
- if (u[i] == 2) {
- ansr.pb(i + 1);
- }
- }
- for (int i = 0; i < sz(v); i++) {
- if (v[i] == 1) {
- ansl.pb(sz(u) + i + 1);
- }
- if (v[i] == 2) {
- ansr.pb(sz(u) + i + 1);
- }
- }
- if (sz(ansl) + sz(ansr) > 0) {
- cout << sz(ansl) << endl;
- for (int x : ansl) {
- cout << x << " ";
- }
- cout << endl << sz(ansr) << endl;
- for (int x : ansr) {
- cout << x << " ";
- }
- exit(0);
- }
- }
- signed main() {
- #ifdef LOCAL
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- cout << fixed << setprecision(9);
- ios::sync_with_stdio(false);
- cin.tie();
- cout.tie();
- int n, m;
- cin >> n >> m;
- vector < int > a(n);
- for (int& x : a) {
- cin >> x;
- }
- vector < pair < int, mask > > l, r;
- for (mask mm(n / 2); mm; ++mm) {
- int sum = 0;
- for (int i = 0; i < n / 2; i++) {
- if (mm[i] == 1) {
- sum = mod(sum + a[i], m);
- }
- if (mm[i] == 2) {
- sum = mod(sum - a[i], m);
- }
- }
- l.pb({ sum, mm });
- }
- for (mask mm(n / 2 + n % 2); mm; ++mm) {
- int sum = 0;
- for (int i = n / 2, j = 0; i < n; i++, j++) {
- if (mm[j] == 1) {
- sum = mod(sum + a[i], m);
- }
- if (mm[j] == 2) {
- sum = mod(sum - a[i], m);
- }
- }
- r.pb({ sum, mm });
- }
- sort(l.begin(), l.end());
- sort(r.begin(), r.end());
- for (auto& [x, mm] : l) {
- auto ptr = lower_bound(r.begin(), r.end(), mp(-x, mask()));
- if (ptr->first == -x) {
- print(mm, ptr->second);
- if (ptr != r.end() && (ptr + 1)->first == -x) {
- print(mm, (ptr + 1)->second);
- }
- }
- ptr = lower_bound(r.begin(), r.end(), mp(m - x, mask()));
- if (ptr->first == m - x) {
- print(mm, ptr->second);
- if (ptr != r.end() && (ptr + 1)->first == m - x) {
- print(mm, ptr->second);
- }
- }
- }
- cout << -1;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement