prompt string | response string |
|---|---|
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.
The GCD of a group of integers is the largest non-negative integer that divides all the integ... | #include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e6 + 5;
const double delta = 1e-8;
const long long mod = 998244353;
const int magic_const = 1e9;
mt19937 gen(54323244234);
long long get_rand(long long x) { return (gen() % x + x) % x; }
struct ev {
double coord;
int type;
int mincost;
};
const bool... |
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.
The GCD of a group of integers is the largest non-negative integer that divides all the integ... | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000 * 1000;
int a[MAXN];
int init_a[MAXN];
int gcd(int a, int b) {
while (a > 0) {
b = b % a;
swap(a, b);
}
return b;
}
vector<int> get_prime(int a) {
vector<int> res;
for (int i = 2; i * i <= a; i++) {
if (a % i == 0) {
res.pus... |
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.
The GCD of a group of integers is the largest non-negative integer that divides all the integ... | #include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int A[maxn];
int cnt[maxn];
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
using namespace std;
int main() {
srand(19260817);
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cnt[i] = i;
}
for (int i = 1; i <= n; i++) {
... |
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.
The GCD of a group of integers is the largest non-negative integer that divides all the integ... | #include <bits/stdc++.h>
using namespace std;
template <class P, class Q>
ostream& operator<<(ostream& stream, pair<P, Q> v) {
stream << "(" << v.first << ',' << v.second << ")";
return stream;
}
template <class T>
ostream& operator<<(ostream& stream, const vector<T> v) {
stream << "[ ";
for (int i = 0; i < (in... |
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.
The GCD of a group of integers is the largest non-negative integer that divides all the integ... | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 105000;
int n;
int a[MAXN];
bool used[MAXN];
int dp[(1 << 20) + 123];
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
vector<int> factorize(int x) {
vector<int> factors;
for (int i = 2; i * i <= x; i++) {
... |
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.
The GCD of a group of integers is the largest non-negative integer that divides all the integ... | #include <bits/stdc++.h>
using namespace std;
const long long INF = (long long)(1e18);
const long long inf = 1e9 + 7;
long double eps = 1e-6;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
long long mod = 998244853;
long lo... |
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.
The GCD of a group of integers is the largest non-negative integer that divides all the integ... | #include <bits/stdc++.h>
using namespace std;
vector<int> pr;
void calcprimes() {
bitset<65536> siv;
for (int i = 2; i < 32767; i++)
if (!siv[i]) {
for (int j = i * i; j < 32768; j += i) siv[j] = true;
pr.push_back(i);
}
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
vector<int> vi;
v... |
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.
The GCD of a group of integers is the largest non-negative integer that divides all the integ... | import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.*;
public class Test {
static PrintWriter writer =
new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
int n;
int[] a;
static int readInt() {
... |
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.
The GCD of a group of integers is the largest non-negative integer that divides all the integ... | #include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (!b) return a;
return gcd(b, a % b);
}
long long fpow(long long x, long long y, long long mod) {
long long ans = 1ll;
for (; y; y >>= 1) {
if (y & 1) ans = ans * x % mod;
x = x * x % mod;
}
return ans;
}
const... |
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.
The GCD of a group of integers is the largest non-negative integer that divides all the integ... | #include <bits/stdc++.h>
using namespace std;
void read(int &x) {
x = 0;
int f = 1;
char ch = getchar();
for (; !isdigit(ch); ch = getchar())
if (ch == '-') f = -f;
for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
x *= f;
}
void print(int x) {
if (x < 0) putchar('-'), x = -x;
if (!x) retur... |
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.
The GCD of a group of integers is the largest non-negative integer that divides all the integ... | #include <bits/stdc++.h>
using namespace std;
struct point {
int x, num;
} w[101000];
int i, n, G[101000], chk[101000];
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int main() {
srand(1879);
scanf("%d", &n);
for (i = 1; i <= n; i++) {
scanf("%d", &w[i].x);
w[i].num = i;
}
clock_t tt = clo... |
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.
The GCD of a group of integers is the largest non-negative integer that divides all the integ... | #include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, m, e[N], f[N];
inline int read() {
int x = 0, p = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') p = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = getchar();
}
re... |
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.
The GCD of a group of integers is the largest non-negative integer that divides all the integ... | #include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 10;
int n, a[maxn], col[maxn], pos[maxn];
int gcd(int a, int b) { return (a % b == 0) ? (b) : (gcd(b, a % b)); }
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i <= n; i++) pos[i] = i;
int cas... |
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.
The GCD of a group of integers is the largest non-negative integer that divides all the integ... | #include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
template <typename T>
inline void rd(T& x) {
int f = 0, c;
while (c = getchar(), c < 48 || 57 < c) f ^= !(c ^ 45);
x = (c & 15);
while (c = getchar(), 47 < c && c < 58) x = x * 10 + (c & 15);
if (f) x = -x;
}
template <typename T>
inline... |
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.
The GCD of a group of integers is the largest non-negative integer that divides all the integ... | #include <bits/stdc++.h>
using namespace std;
int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const int MAXN = 1e5 + 7;
int ans[MAXN];
pair<int, int> a[MAXN];
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n... |
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.
The GCD of a group of integers is the largest non-negative integer that divides all the integ... | #include <bits/stdc++.h>
using namespace std;
int n;
struct data {
int v, id;
} a[100100];
int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
int bel[100100];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) scanf("%d", &a[i].v), a[i].id = i;
int tot = 100;
int g1, g2;
while (tot--) {
ran... |
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.
The GCD of a group of integers is the largest non-negative integer that divides all the integ... | #include <bits/stdc++.h>
std::mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count());
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int as[100005];
int assign[100005];
int main() {
int N;
scanf("%d", &N);
for (int i = 0; i < N; i++) {
scanf("%d", &as[i]);
}
std::vector<int> ord... |
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.
The GCD of a group of integers is the largest non-negative integer that divides all the integ... | //package round576;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.Map;
import java.util.Set;
import java.util.... |
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.
The GCD of a group of integers is the largest non-negative integer that divides all the integ... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.util.StringTokenizer;
import java.util.Random;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;... |
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.
The GCD of a group of integers is the largest non-negative integer that divides all the integ... | #include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vpii = vector<pii>;
const int MAXK = 22;
const int MAXN = 100500;
const int MAX_MASK = 512;
vpii a;
int n, m;
int num[MAXK * MAXK][3];
int backet1[MAXK];
int backet2[MAXK];
int ans[MAXN];
int was[MAX_MASK][MAX_MASK];... |
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.
The GCD of a group of integers is the largest non-negative integer that divides all the integ... | import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.*;
public class Test {
static PrintWriter writer =
new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
int n;
int[] a;
static int readInt() {
... |
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.
The GCD of a group of integers is the largest non-negative integer that divides all the integ... | #include <bits/stdc++.h>
using namespace std;
int rd() {
int k = 0, f = 1;
char c = getchar();
while (!isdigit(c)) {
if (c == '-') f = -1;
c = getchar();
}
while (isdigit(c)) {
k = (k << 1) + (k << 3) + c - 48;
c = getchar();
}
return k * f;
}
void wr(int x) {
if (x < 0) putchar('-'), x ... |
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.
The GCD of a group of integers is the largest non-negative integer that divides all the integ... | #include <bits/stdc++.h>
#pragma optimize("Ofast")
using namespace std;
const int inf = 0x3f3f3f3f;
const double eps = 1e-6;
const int mod = 1000000007;
inline string getstr(string &s, int l, int r) {
string ret = "";
for (int i = l; i <= r; i++) ret.push_back(s[i]);
return ret;
}
int modpow(int x, int y, int md ... |
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.
The GCD of a group of integers is the largest non-negative integer that divides all the integ... | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
int n;
pair<int, int> T[MAXN];
pair<int, int> A[MAXN];
unordered_map<int, vector<int>> pos;
vector<int> cntm2;
map<pair<int, int>, tuple<int, int, int, int>> DP_cur, DP_prev;
int solution[MAXN];
int lastx = -1;
int lasty = -1;
int lastr = -1;
long l... |
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.
The GCD of a group of integers is the largest non-negative integer that divides all the integ... | #include <bits/stdc++.h>
const int MAXN = 100010;
int n, A[MAXN];
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
std::vector<int> factor(int x) {
std::vector<int> res;
for (int i = 2; i * i <= x; ++i)
if (x % i == 0) {
res.push_back(i);
while (x % i == 0) x /= i;
}
if (x > 1) res.push... |
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.
The GCD of a group of integers is the largest non-negative integer that divides all the integ... | #include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll rnd() {
ll x = 0;
for (int i = 0; i <= 17; ++i) x = 10 * x + rand() % 10;
return x;
}
const int N = 1e5 + 100;
const int K = 9;
const int M = 2 * K * K;
const int S = 1 << (K + K);
int n, a[N], skad[M][S];
bool dp[M][S];
vector<int> factorize(... |
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.
The GCD of a group of integers is the largest non-negative integer that divides all the integ... | #include <bits/stdc++.h>
using namespace std;
const int __SIZE = 1 << 18;
char ibuf[__SIZE], *iS, *iT;
template <typename T>
inline void read(T &x) {
char ch, t = 0;
x = 0;
while (!isdigit(ch = (iS == iT
? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),
... |
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.
The GCD of a group of integers is the largest non-negative integer that divides all the integ... | #include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int FFTMOD = 119 << 23 | 1;
const int INF = (int)1e9 + 23111992;
const long long LINF = (long long)1e18 + 23111992;
const long double PI = acos((long double)-1);
const long double EPS = 1e-9;
inline long long gcd(long long a, long long b)... |
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.
The GCD of a group of integers is the largest non-negative integer that divides all the integ... | #include <bits/stdc++.h>
using namespace std;
inline int read() {
int w = 0, x = 0;
char c = getchar();
while (!isdigit(c)) w |= c == '-', c = getchar();
while (isdigit(c)) x = x * 10 + (c ^ 48), c = getchar();
return w ? -x : x;
}
namespace star {
const int maxn = 1e5 + 10;
mt19937 rd(chrono::system_clock::n... |
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.
The GCD of a group of integers is the largest non-negative integer that divides all the integ... | #include <bits/stdc++.h>
using namespace std;
int n, a[100005], num[100005], ans[100005];
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') f = -1;
ch = getchar();
}
while (isdigit(ch)) {
(x *= 10) += ch - '0';
ch = getchar();
}
return x * f;
... |
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.
The GCD of a group of integers is the largest non-negative integer that divides all the integ... | #include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int p[100010];
int a[100010];
int res[100010];
const int M = 5000000;
int main() {
srand(time(0));
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
p[i] = i;
}
long lo... |
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.
The GCD of a group of integers is the largest non-negative integer that divides all the integ... | #include <bits/stdc++.h>
using namespace std;
using std::cin;
using std::cout;
using std::endl;
namespace IN {
const int Max_Input_Number = 1000000;
char buf[Max_Input_Number], *p1, *p2;
template <typename T>
inline int input(T &x) {
static std::streambuf *inbuf = cin.rdbuf();
x = 0;
register int f = 0, flag = 1;... |
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.
The GCD of a group of integers is the largest non-negative integer that divides all the integ... | #include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int gi() {
int x = 0, o = 1;
char ch = getchar();
while (!isdigit(ch) && ch != '-') ch = getchar();
if (ch == '-') o = -1, ch = getchar();
while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
return x * o;
}
int n, a[N], st[N], tp =... |
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.
The GCD of a group of integers is the largest non-negative integer that divides all the integ... | import sys
def gcd(l):
if len(l)==0:
return 0
if len(l)==1:
return l[0]
if len(l)==2:
if l[1]==0:
return l[0]
return gcd([l[1],l[0]%l[1]])
return gcd([gcd(l[:-1]),l[-1]])
def brute_force(l1,l2,l,sol):
if len(l)==0:
g1=gcd(l1)
g2=gcd(l2)
r... |
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.
The GCD of a group of integers is the largest non-negative integer that divides all the integ... | #include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
int n;
long long a[100000];
pair<long long, int> arr[100000];
long long gcd(long long num1, long long num2) {
if (num1 >... |
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.
The GCD of a group of integers is the largest non-negative integer that divides all the integ... | #include <bits/stdc++.h>
using namespace std;
template <typename T>
void chkmax(T &x, T y) {
x = x > y ? x : y;
}
template <typename T>
void chkmin(T &x, T y) {
x = x < y ? x : y;
}
template <typename T>
void read(T &x) {
x = 0;
bool w = 0;
char ch = 0;
for (; !isdigit(ch); ch = getchar()) w |= ch == '-';
... |
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.
The GCD of a group of integers is the largest non-negative integer that divides all the integ... | #include <bits/stdc++.h>
using namespace std;
inline int read() {
int SUM = 0, ff = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') ff = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
SUM = (SUM << 3) + (SUM << 1) + (ch ^ 48);
ch = getchar();
}
return SUM * ff... |
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.
The GCD of a group of integers is the largest non-negative integer that divides all the integ... | #include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
using namespace std;
template <typename _T>
inline void read(_T &f) {
f = 0;
_T fu = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') fu = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
f = (f << 3) + ... |
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.
The GCD of a group of integers is the largest non-negative integer that divides all the integ... | #include <bits/stdc++.h>
std::mt19937 rng(
(int)std::chrono::steady_clock::now().time_since_epoch().count());
const int ms = 100100;
std::vector<int> primes;
bool isPrime(int x) {
if (x < 2) return false;
for (auto p : primes) {
if (p * p > x) break;
if (x % p == 0) return false;
}
return true;
}
st... |
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.
The GCD of a group of integers is the largest non-negative integer that divides all the integ... | #include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
cerr.writ... |
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.
The GCD of a group of integers is the largest non-negative integer that divides all the integ... | #include <bits/stdc++.h>
using namespace std;
std ::mt19937 ran(20040924);
int n, a[100000], p, q, fp[9], fq[9], lp, lq, able[100000], List[325], L,
mask1[325], mask2[325], res[100000];
char dp[325][512][512];
template <typename T>
inline void chkmin(T &x, T y) {
x = min(x, y);
}
template <typename T>
inline void... |
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.
The GCD of a group of integers is the largest non-negative integer that divides all the integ... | #include <bits/stdc++.h>
using namespace std;
int n;
pair<int, int> s[100005];
int belong[100005];
clock_t base = clock();
struct division {
int p[100005], v[100005], total, temp;
division() {
memset(p, 0, sizeof(p));
memset(v, 0, sizeof(v));
total = temp = 0;
}
void init() {
for (int i = 1; i <... |
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.
The GCD of a group of integers is the largest non-negative integer that divides all the integ... | #include <bits/stdc++.h>
using namespace std;
int P[100005], c1, c2, g1[20], g2[20], pos[400], st1, mn, st2, e, n, i, j, k,
from[170][1 << 9][1 << 9], p[100005], a[100005], cnt, u1[20], u2[20],
is[100005];
inline int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
void check(int now, int f1, int f2) {
if ... |
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.
The GCD of a group of integers is the largest non-negative integer that divides all the integ... | #include <bits/stdc++.h>
const int MAXN = 1e5 + 10;
int n, a[MAXN], id[MAXN], ans[MAXN];
int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]), id[i] = i;
clock_t st = clock();
while (clock() - st < 0.5 * CLOCKS_PER_SEC) {
std::... |
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.
The GCD of a group of integers is the largest non-negative integer that divides all the integ... | #include <bits/stdc++.h>
using std::make_pair;
template <typename T>
inline T read() {
T x = 0;
char ch = std::getchar();
bool f = 0;
while (!std::isdigit(ch)) {
f = (ch == '-');
ch = std::getchar();
}
while (std::isdigit(ch)) {
x = x * 10 + (ch - '0');
ch = std::getchar();
}
return f ? ... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | #include <bits/stdc++.h>
using namespace std;
long long n, x;
long long num[21], f[1 << 20], g[21][21];
int main() {
cin >> n;
for (; n--;) {
cin >> x;
++num[--x];
for (int i = 0; i < 20; ++i) g[x][i] += num[i];
}
for (int i = 0; i < 1 << 20; ++i) f[i] = 1e18;
f[0] = 0;
for (int i = 0; i < 1 << ... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | #include <bits/stdc++.h>
long long dp[1100005];
long long f[25][25];
int a[400005];
int num[25];
int main() {
int n;
std::cin >> n;
for (int i = 1; i <= n; i++) {
std::cin >> a[i];
num[a[i]]++;
for (int j = 1; j <= 20; j++) {
if (a[i] != j) f[a[i]][j] += num[j];
}
}
for (int i = 1; i < (... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | #include <bits/stdc++.h>
const long long INF = 2000000005;
const long long BIG_INF = 2000000000000000005;
const long long mod = 1000000007;
const long long P = 31;
const long double PI = 3.141592653589793238462643;
const double eps = 1e-9;
using namespace std;
vector<pair<long long, long long> > dir = {{-1, 0}, {0, 1},... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | #include <bits/stdc++.h>
using namespace std;
const int C = 20;
const int MAXN = 4e5 + 10;
int a[MAXN];
vector<int> c[C];
long long cost[C][C];
long long dp[1 << C];
long long eval(const vector<int> &v, int f, int s) {
int n = v.size();
long long tot = 0;
long long ans = 0;
for (int i = 0; i < n; i++) {
if ... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | import java.io.*;
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.util.Comparator.*;
public class Main {
FastScanner in;
PrintWriter out;
ArrayList<Integer>[] graph;
ArrayList<GraphPair>[] weightedGraph;
... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | #include <bits/stdc++.h>
using namespace std;
const int mx = (1 << 20), N = 25;
long long dp[mx], tot[25], cnt[N][N];
int main() {
int n, x;
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d", &x);
x--;
for (int j = 0; j < 20; ++j) cnt[x][j] += tot[j];
tot[x]++;
}
memset(dp, 0x3f, size... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | #include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) { cerr << endl; }
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << " ";
err(++it, args...);
}
long long mod(long long x, long long m = 1000000007) { retu... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | #include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 7;
const long long M = 21;
long long INF = 1e18;
long long n;
long long d[(1 << M)];
long long cnt[M][M];
vector<long long> col[M];
int32_t main() {
ios::sync_with_stdio(0);
cin >> n;
for (long long i = 0; i < n; i++) {
long long x;
c... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | #include <bits/stdc++.h>
using namespace std;
long long cur, allmask;
long long a[400001];
long long to[20][20], cnt[20 + 1];
long long dp[(1 << 20)];
long long solve(long long mask) {
if (mask == allmask) return 0;
long long &res = dp[mask];
if (res != -1) return res;
res = 1e14;
long long idx = __builtin_po... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | #include <bits/stdc++.h>
long long mod = 1000000007;
long long mod2 = 998244353;
long long OO = 1e18;
long long david_villa_pow(long long x, long long n) {
if (n == 0) return 1;
long long u = david_villa_pow(x, n / 2);
u = ((u) * (u));
if (n % 2 == 1) u = ((u) * (x));
return u;
}
long long up(long long x, lon... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | #include <bits/stdc++.h>
#pragma gcc optimize("O3")
#pragma gcc optimize("unroll-loops")
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int N = 4e5 + 10, M = 20;
const ll INF = 1e18;
int n;
int ar[N];
ll cnt[M][M];
ll dp[(1 << M)];
int main() {
ios_base::sync_with_stdio(false);
cin.tie... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | #include <bits/stdc++.h>
using namespace std;
const long long MAXX = 2000000000000000009;
long long inv[20][20];
long long dp[(1 << 20)];
long long pom[20];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, tab[400009];
cin >> n;
int a;
for (int i = 0; i < n; i++) {
cin >> tab[i];
... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
FastScanner sc = new FastScanner();
int N = sc.nextInt();
int[] nums = new int[N];
ArrayList<Integer>[] locs = new ArrayList[20];
for (int i = 0; i < 20; i... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | import java.util.*;
import java.io.*;
public class tr0 {
static PrintWriter out;
static StringBuilder sb;
static int mod = 998244353;
static long inf = (long) 1e18 + 1;
static int[] col;
static int n, m;
static TreeSet<Integer>[] ad;
static long[] memo,cnt[];
static HashSet<Integer> h;
static int[] pos, ones... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;
public class E {
//Solution by Sathvik Kuthuru
public static void main(String[] args) {
FastReader scan = new FastReader();
PrintWriter out = new PrintWriter(System.... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | import java.lang.*;
import java.util.*;
import java.io.*;
public class Main {
void solve() {
int n=ni();
int cnt[]=new int[20];
long dp2[][]=new long[20][20];
for(int i=1;i<=n;i++){
int x=ni()-1;
for(int y=0;y<20;y++) dp2[x][y]+=cnt[y];
cnt[x]++;... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | #include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const int MX = 21;
vector<long long> pos[MX];
const int MSK = 1 << 20;
bool used[MSK];
long long dp[MSK];
long long cost[MX];
long long delta[MX][MX];
int cnt = 0;
int getBit(int mask, int i) { return (mask >> i) & 1; }
void turnOff(int &mask, in... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | #include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const int MX = 21;
vector<long long> pos[MX];
const int MSK = 1 << 20;
bool used[MSK];
long long dp[MSK];
long long cost[MX];
long long delta[MX][MX];
int cnt = 0;
int getBit(int mask, int i) { return (mask >> i) & 1; }
void turnOff(int &mask, in... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | #include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7, maxn = 4e5 + 5, maxm = 20, inf = 1e18 + 5;
int a[maxn], cnt[maxm];
long long t[maxm][maxm];
long long f[maxm][1 << maxm], dp[1 << maxm];
int main() {
long long n;
cin >> n;
map<int, int> d;
for (int i = (0); i < n; i++) {
cin >> a[... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | import java.io.*;
import java.util.*;
public class E implements Runnable {
public static void main (String[] args) {new Thread(null, new E(), "_cf", 1 << 28).start();}
int n, a[];
long[][] cnt;
long[] dp;
public void run() {
FastScanner fs = new FastScanner();
PrintWriter out = new PrintWriter(System.out);... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | import java.util.*;
import java.lang.*;
import java.io.*;
public class Main
{
public static void main (String[] args) throws java.lang.Exception
{
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outp... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.net.Inet4Address;
import java.util.*;
import java.lang.*;
import java.util.HashMap;
import java.util.PriorityQueue;
public class Solution implements Runnable
{
static class pair implements Comparable
{
int f;
... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | #include <bits/stdc++.h>
using namespace std;
int n, a[400010], cnt[21];
long long inv[21][21], f[(1 << 21) + 1];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d", a + i);
for (int j = 1; j <= 20; ++j) inv[a[i]][j] += cnt[j];
++cnt[a[i]];
}
for (int i = 1; i < (1 << 20); ++i) ... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | #include <bits/stdc++.h>
using namespace std;
const long long M = 1 << 20;
long long I[M];
long long n;
long long cnt[20];
long long e[20][20];
long long E[20][M];
long long dp[M];
int32_t main() {
for (long long i = 0; i < 20; i++) I[1 << i] = i;
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (long long ... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | #include <bits/stdc++.h>
long long n, x, num[21], f[1 << 21], ans, i, j, g[21][21], s, k;
int main() {
scanf("%lld", &n);
for (; n--;) {
scanf("%lld", &x);
num[--x]++;
for (i = 0; i < 20; i++) g[x][i] += num[i];
}
memset(f, 63, sizeof(f));
f[0] = 0;
for (i = 0; i < 1 << 20; i++)
for (j = 0; ... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | #include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using i32 = int;
using i64 = long long;
using u8 = unsigned char;
using u32 = unsigned;
using u64 = unsigned long long;
usin... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vii = vector<ii>;
const ll MOD = 998244353;
const ll INF = 1e18 + 9;
const int MAXN = 1000006;
const int MAXC = 20;
int n, arr[MAXN], num[MAXC];
ll dist[MAXC][MAXC], mem[1... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | #include <bits/stdc++.h>
using namespace std;
long long n, cnt[21][21], pos[21][400001], dp[1 << 20];
vector<long long> v[21];
signed main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(false);
cin >> n;
for (long long i = 1; i <= n; i++) {
long long a;
cin >> a;
a--;
v[a].push_back(i)... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.net.Inet4Address;
import java.util.*;
import java.lang.*;
import java.util.HashMap;
import java.util.PriorityQueue;
public class Solution implements Runnable
{
static class pair implements Comparable
{
int f;
... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | #include <bits/stdc++.h>
const int maxn = 4e5 + 10;
const int maxm = 2e5 + 10;
const int inf = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
const double eps = 1e-7;
using namespace std;
long long cnt[25][25], dp[1 << 21];
int n;
vector<int> col[25];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | #include <bits/stdc++.h>
using namespace std;
int n;
long long s[32][32];
int a[400010];
const int M = 20;
long long f[1 << M];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i <= M; i++)
for (int j = 1; j <= M; j++) {
if (i == j) continue;
int cnt =... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | import java.util.*;
import java.io.*;
public class Main {
public static void main(String args[]) {new Main().run();}
FastReader in = new FastReader();
PrintWriter out = new PrintWriter(System.out);
void run(){
work();
out.flush();
}
long mod=998244353;
long gcd(long a,long b) {
return b==0?a:gcd(b,a%b);
... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | #include <bits/stdc++.h>
int inp() {
char c = getchar();
int neg = 1;
while (c < '0' || c > '9') {
if (c == '-') neg = -1;
c = getchar();
}
int sum = 0;
while (c >= '0' && c <= '9') {
sum = sum * 10 + c - '0';
c = getchar();
}
return sum * neg;
}
long long nx[30][30];
long long f[2000000... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | #include <bits/stdc++.h>
using namespace std;
long long cur, allmask;
long long a[400001];
long long to[20][20], cnt[20 + 1];
long long dp[20][(1 << 20)];
long long solve(long long idx, long long mask) {
if (idx == cur || mask == allmask) return 0;
long long &res = dp[idx][mask];
if (res != -1) return res;
res ... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | #include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 9;
const int M = 20 + 1;
const long long INF = 1000 * 1000 * 1000 * 1LL * 1000 * 1000 * 1000;
int n;
long long d[1 << M];
long long cnt[M][M];
vector<int> col[M];
void init() {
for (int i = 0; i < 20; i++) {
for (int j = 0; j < 20; j++) {
if ... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1 << 21;
const long long INF = 0x3f3f3f3f3f3f3f3f;
vector<int> pos[25];
long long dp[maxn];
long long cost[25][25];
int main(void) {
int tot = 1 << 20;
int i, j, k, n, v;
scanf("%d", &n);
for (i = 1; i <= n; i++) {
scanf("%d", &v);
v--;
... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 0x3f3f3f3f;
const int maxn = 4e5 + 1;
const int mod = 1e9 + 7;
using pii = pair<int, int>;
int n;
int a[maxn], b[maxn], N;
ll dp[1 << 20];
ll f[20][20];
ll sum[20][maxn], cost[20][1 << 20];
vector<int> v[20];
int main() {
ios::sync_wi... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Arrays;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.util.HashMap;
import java.io.InputStream;
/**
* @author khokharnikunj8
... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | import java.lang.reflect.Array;
import java.util.*;
import java.io.*;
public class E {
public static void main(String[] args) {
FastScanner scanner = new FastScanner();
PrintWriter out = new PrintWriter(System.out, false);
int n = scanner.nextInt();
int[] arr = new int[n];
f... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | #include <bits/stdc++.h>
using namespace std;
const int nmax = 4e5 + 10;
const int cmax = 20;
int marbles[nmax];
long long cost[cmax][cmax];
int fv[cmax];
long long dp[1 << cmax];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; ++i) cin >> marbles[i];
for (int i = n; i >= 1; --i) {
int curentColor = -... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | import java.util.*;
import java.io.*;
public class EdC {
static long[] mods = {1000000007, 998244353, 1000000009};
static long mod = mods[0];
public static MyScanner sc;
public static PrintWriter out;
public static void main(String[] omkar) throws Exception{
// TODO Auto-generated method stub
sc = new MySc... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | #include <bits/stdc++.h>
using namespace std;
bool checkbit(int mask, int bit) { return mask & (1 << bit); }
int setbit(int mask, int bit) { return mask | (1 << bit); }
vector<int> v[22];
vector<int> w;
long long int invCnt[22][22];
long long int dp[(1 << 22) - 1 + 100];
long long int lastMask;
long long int f(int mask... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | #include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<int> v(n);
for (int &i : v) {
cin >> i;
i--;
}
vector<vector<long long>> bv(n, vector<long long>(20)),
b2(20, vector<long long>(20));
for ... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | #include <bits/stdc++.h>
using namespace std;
int a[400005];
vector<int> v[20];
long long sum[20][20];
long long dp[1 << 20];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
a[i]--;
v[a[i]].push_back(i);
}
for (int i = 0; i < 20; i++) {
for (int j = 0; j... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | #include <bits/stdc++.h>
using namespace std;
const int N = (int)4e5 + 7;
const int M = 20;
int n, a[N];
vector<int> u[M];
set<int> s;
int t[M];
long long dp[(1 << M)];
int bits[M], top;
bool act[M];
long long score[M][M];
int cnt(int col, int p) {
int l = 0, r = (int)u[col].size() - 1, ans = 0;
while (l <= r) {
... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | /*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
lets do this
*/
import java.util.*;
import java.io.*;
public class x1215E
{
... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | #include <bits/stdc++.h>
using namespace std;
void file(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
template <typename Tp>
void read(Tp &x) {
long long fh = 1;
char c = getchar();
x = 0;
while (c > '9' || c < '0') {
if (c == '-') {
fh = -1;
... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | //package round585;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
public class E2 {
InputStream is;
PrintWriter out;
String INPUT = "";
void solve()
{
int n = ni();
in... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | #include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cer... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | import java.io.*;
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.util.Comparator.*;
public class Main {
FastScanner in;
PrintWriter out;
ArrayList<Integer>[] graph;
ArrayList<GraphPair>[] weightedGraph;
... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | #include <bits/stdc++.h>
using namespace std;
long long cur, allmask;
long long a[400001];
long long to[20][20], cnt[20 + 1];
long long dp[(1 << 20)];
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long n;
cin >> n;
for (long long i = 0; i < n; i++) {
cin >> a[i];
cnt[a[i... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | #include <bits/stdc++.h>
using namespace std;
long long dp[1 << 20ll];
long long addon[1 << 20ll][20];
long long arr[400009];
long long adder[21][21];
long long sumas[21];
int Modifiedlog2(int A) {
int curr = 1;
int ret = 0;
while (curr != A) {
curr *= 2;
ret++;
}
return ret;
}
int main() {
long lon... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | #include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 7;
const int S = 20;
const int M = (1 << S) - 1;
const long long INF = 1e19;
long long f[(1 << S) + 5], g[S + 5][S + 5], p[S + 5];
int main() {
int n;
int i, j, k;
long long x, y;
cin >> n;
for (i = 1; i <= n; i++) {
cin >> k;
k--;
... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | import java.util.*;
public class Main {
public static int MAX = 20;
public static int n;
public static int[] arr, pow, pos;
public static long[][] cnt;
public static long[] dp;
public static int[][] min;
public static void main(String[] args) {
pow = new int[MAX + 2];
pow[0] ... |
Problem: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color).
In other words, Monocarp wants ... | #include <bits/stdc++.h>
using namespace std;
long long f[(1 << 20) + 10], num[21], sum[21][21];
int main() {
int n, m = 20;
scanf("%d", &n);
for (int i = 1, x; i <= n; i++) {
scanf("%d", &x);
x--, num[x]++;
for (int j = 0; j < 20; j++) {
sum[j][x] += num[j];
}
}
memset(f, 0x3f, sizeof f... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.