solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int n, m, h, s, A[1005];
double ans = 1;
int main() {
scanf("%d%d%d", &n, &m, &h);
for (int i = 1; i <= m; i++) scanf("%d", &A[i]), s += A[i];
if (s < n) {
printf("-1");
return 0;
}
n--;
s--;
A[h]--;
for (int i = 0; i < n; i++) ans *= 1.0 * (s - A[h]... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
if (s[0] >= 97 && s[0] <= 122) s[0] -= 32;
cout << s;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
cout << n << endl;
for (int i = 0; i < n; i++)
cout << "1"
<< " ";
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int N, M;
string S;
int pre[45][2];
int A[45][45][2][2];
long long dp[45][45][45][45][2][2];
bool check(string& cur) {
for (int i = 0; i + M <= cur.size(); i++)
if (S == cur.substr(i, M)) return true;
return false;
}
int main() {
ios::sync_with_stdio(0);
cin >> ... | 21 |
#include <bits/stdc++.h>
using namespace std;
int solve(int n, string s) {
int res = 0;
int ct = 0;
for (char c : s) {
if (c == '(') {
res++;
if (res > 0) {
ct++;
}
} else {
res--;
}
}
return res == 0 ? s.size() - 2 * ct : -1;
}
int main(int argc, char const *argv[]... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MaxSize = 100;
void speed_code() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
string uppercase(string s) {
transform(s.begin(), s.end(), s.begin(), ::toupper);
return s;
}
string lowercase(string s) {
transform(s.begin(), s.end(), s.begin... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cout << setprecision(32);
int n;
cin >> n;
if (n % 10 < 5) {
n /= 10;
n *= 10;
} else {
n /= 10;
n *= 10;
n += 10;
}
cout << n << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long n, k;
cin >> n >> k;
long arr[n];
long as[n];
long h = 0;
for (int i = 1; i <= n; i++) {
long x;
cin >> x;
arr[i] = x;
as[i] = 0;
}
for (int i = 2; i <= k - 1; i++... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long GCD(long long x, long long y) {
if (y == 0) return x;
return GCD(y, x % y);
}
long long LCM(long long x, long long y) { return (x * y) / (GCD(x, y)); }
long long LOGK(long long x, long long k) {
if (x >= k) return 1 + LOGK(x / k, k);
return 0;
}
long long ... | 9 |
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> PII;
long long qpow(long long a, long long b, long long m) {
long long ans = 1;
while (b) {
if (b & 1) ans = ans * a % m;
a = a * a % m, b >>= 1;
}
return ans;
}
long long qpow(long long a, long long b) {
long long ans = 1;
while (... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MXN = 1e6 + 30;
const int MAXN = 1e3 + 123;
const long long INF = 1e9 + 7;
const long long BINF = 1e15;
const int MOD = 1e9 + 7;
const long double EPS = 1e-9;
long long t;
long long n;
string a[MXN];
long long m;
string b[MXN], ans[MXN];
vector<string> name[MAXN];... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int oo = 1e9;
const int maxn = 3e5 + 1;
int n, m, d[maxn], trade[maxn];
vector<int> e[maxn];
void Enter() {
cin >> n >> m;
for (int m2 = m; m2 > 0; --m2) {
int u, v;
cin >> u >> v;
e[u].push_back(v);
e[v].push_back(u);
}
}
void Init() {}
void BFS... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long t;
t = 1;
while (t--) {
int n, k;
cin >> n >> k;
string a;
cin >> a;
vector<int> v(k);
for (auto i : a) v[i - 'A'] += 1;
cout << *min_element((v).begin(... | 0 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n, m, i;
cin >> n >> m;
long long a[n + 5];
double ans = 0;
for (i = 1; i <= n; i++) {
cin >> a[i];
}
long long u, v, c;
double local = 0;
for (i = 0; i < m; i++) {
cin >> u >> v >> c;
local = 1.0 * (a[u] + a[v]) / c;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void pr(vector<T> &v) {
for (int i = 0; i < (int)(v).size(); i++) cout << v[i] << " ";
cout << '\n';
;
}
template <typename T>
void pr(vector<vector<T>> &v) {
for (int i = 0; i < (int)(v).size(); i++) {
pr(v[i]);
}
}
template <typename T>... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int q;
cin>>q;
while(q--)
{
long long a, b, n;
cin>>a>>b>>n;
long long x=a&-a, y=b&-b;
if(x*y>=n) cout<<"YES\n"; else cout<<"NO\n";
}
return 0;
... | 0 |
#include <bits/stdc++.h>
template <class T>
T gcd(T a, T b) {
T r;
while (b != 0) {
r = a % b;
a = b;
b = r;
}
return a;
}
template <class T>
T lcm(T a, T b) {
return a / gcd(a, b) * b;
}
using namespace std;
int prime(int n) {
for (int i = 2; i * i <= n; i++)
if (n % i == 0) return 0;
ret... | 10 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
long long n;
cin >> n;
vector<long long> v(n);
for (long long i = 0; i < n; i++) {
cin >> v[i];
}
long long black = 0, white = 0;
for (long long i = 0; i < n; i++) {
long long x = v[i] / 2, y = ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n;
int m;
const int MAXN = 100000 + 10;
vector<int> g[MAXN];
bool used[MAXN];
int timer, tin[MAXN], fup[MAXN];
int mark[MAXN];
set<pair<int, int> > Set;
vector<int> Comp[MAXN];
void IS_BRIDGE(int v1, int v2) {
Set.insert(make_pair(v1, v2));
Set.insert(make_pair(v2, ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, j;
cin >> n;
int arr[7] = {0};
for (i = 0; i < n; i++) {
for (j = 0; j < 7; j++) {
char tmp;
cin >> tmp;
arr[j] += tmp - '0';
}
}
int max = 0;
for (i = 0; i < 7; i++) {
if (arr[i] > max) max = arr[i];
}
... | 1 |
#include <bits/stdc++.h>
using namespace std;
std::vector<long long int> v2;
void sieve(int n) {
bool prime[n + 1];
memset(prime, true, sizeof(prime));
for (int p = 2; p * p <= n; p++) {
if (prime[p] == true) {
for (int i = p * 2; i <= n; i += p) prime[i] = false;
}
}
for (int p = 2; p <= n; p++... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long Max(long long a, long long b) { return a > b ? a : b; }
int main() {
long long t, n, k, d1, d2, m;
int flag;
cin >> t;
while (t--) {
flag = 1;
cin >> n >> k >> d1 >> d2;
if (n % 3 != 0) {
cout << "no\n";
continue;
}
if (k < ... | 9 |
#include <bits/stdc++.h>
#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
const long long MAXN = 1123456;
const long long N = 500000;
const long long inf = 3e18;
mt19937_64 rnd(chrono::system_clock::now().time_since_epoch().count());
template <typename ... | 18 |
#include <bits/stdc++.h>
using namespace std;
int n, t, res;
float L[20][20];
int main() {
cin >> n >> t;
L[1][1] = t;
if (t > 0) ++res;
for (int i = 2; i <= n; i++) {
L[i][1] = (L[i - 1][1] - 1) / double(2);
if (L[i][1] >= 1)
++res;
else
L[i][1] = 1;
L[i][i] = (L[i - 1][i - 1] - 1) ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, m, adj[51][51], temp[51][51], cnt = 0;
int dfs(int x, int y) {
if (temp[x][y] == -1) return 0;
int tor = 1;
temp[x][y] = -1;
if ((x + 1) < n)
if (temp[x + 1][y]) tor += dfs(x + 1, y);
if ((x - 1) > -1)
if (temp[x - 1][y]) tor += dfs(x - 1, y);
if ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
inline long long read() {
long long num = 0, fu = 1;
char c = getchar();
while (c != '-' && (c > '9' || c < '0')) c = getchar();
if (c == '-') fu = -1, c = getchar();
while (c >= '0' && c <= '9')
num = (num << 3) + (num << 1) + (c ^... | 17 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
long long inv[2555];
long long a[55];
long long w[55];
long long dp[55][105][105];
long long n, m, sum;
long long pw(long long n, long long k) {
if (!k) return 1;
long long res = pw(n, k >> 1);
res = res * res % mod;
if (k & 1) retur... | 15 |
#include <bits/stdc++.h>
using namespace std;
bool ss(int a) {
for (int i = 2; i <= sqrt(a); i++) {
if (a % i == 0) return false;
}
return true;
}
int main() {
int n;
cin >> n;
cout << (ss(n) ? 1 : (n % 2 == 0 || ss(n - 2) ? 2 : 3));
}
| 8 |
#include <bits/stdc++.h>
using namespace std;
int len, pt;
char s[1000050];
inline int OR(int a, int b) {
return (1 << max(a, b)) | (a == 1 && b == 1 ? 4 : 0);
}
inline int AND(int a, int b) {
return (1 << min(a, b)) | (a == 1 && b == 1 ? 1 : 0);
}
inline int XOR(int a, int b) {
if (a != 1 && b != 1) {
if (a ... | 18 |
#include <bits/stdc++.h>
#pragma GCC optimize(3)
using namespace std;
const int INF = INT_MAX / 4;
const int dx[] = {0, 0, -1, 1}, dy[] = {-1, 1, 0, 0};
const int maxn = 3e3 + 10;
int mo_num = 1e9 + 7;
int n, m, t, a[maxn], b[maxn], case_of_T;
long long ans;
vector<int> pos[maxn];
int f[maxn][maxn];
void update(int pos... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 4000005;
int n, m, h, g, T, limit1, limit2;
long long a[MAXN], ans;
vector<int> ansl;
bool CanBeDelete(int now) {
int ch = a[now * 2] > a[now * 2 + 1] ? now * 2 : now * 2 + 1;
while (a[ch]) {
now = ch;
ch = a[now * 2] > a[now * 2 + 1] ? now * 2 ... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x1, x2, x3;
cin >> x1 >> x2 >> x3;
int noMax, noMin;
noMax = fmax(x1, fmax(x2, x3));
noMin = fmin(x1, fmin(x2, x3));
cout << noMax - noMin << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long mod;
long long inv[2100000 + 1];
long long kai[2100000 + 1];
long long invkai[2100000 + 1];
void invinit() {
inv[1] = 1;
for (int i = 2; i <= 2100000; i++) {
inv[i] = mod - (mod / i) * inv[mod % i] % mod;
}
kai[0] = invkai[0] = 1;
for (int i = 1; i <... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e6 + 7;
int n, a[maxn];
char s[maxn], t[maxn];
int T;
int main() {
scanf("%d", &T);
while (T--) {
scanf("%d", &n);
int ans = 0;
scanf("%s%s", s + 1, t + 1);
s[0] = s[n + 1] = '0';
for (int i = 1; i <= n; i++) {
if (t[i] == '1'... | 0 |
#include <bits/stdc++.h>
using namespace std;
string s;
int n;
int deg[100001];
int main() {
cin >> n;
for (int i = 1; i < n; i++) {
int u, v;
cin >> u >> v;
deg[u]++;
deg[v]++;
}
int mid = 0;
for (int i = 1; i <= n; i++) {
if (deg[i] > 2) {
if (mid != 0) {
cout << "No\n";
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
string res[55];
string ss[55];
int main() {
cin.sync_with_stdio(false);
cin >> n >> k;
for (int i = (int)(0); i < (int)(2); i++) {
for (int j = (int)(0); j < (int)(26); j++) {
ss[i * 26 + j] = 'a' + j;
ss[i * 26 + j] = (i == 0 ? "A" : "B") + ... | 7 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma comment(linker, "/STACK:2000000")
using namespace std;
template <int D, typename T>
struct Vec : public vector<Vec<D - 1, T>> {
static_assert(D >= 1, "Vector dimension must be greater than zero!");
template <typename...... | 17 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<long long>;
using vl = vector<long long>;
using pii = pair<long long, long long>;
using pll = pair<long long, long long>;
const long long DX[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0},
DY[9] = {-1, 0, 1, 0, -1, 1, 1, -1, 0};
... | 7 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void splitstr(const string &s, vector<T> &out) {
istringstream in(s);
out.clear();
copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out));
}
template <class T>
T gcd(T a, T b) {
return b ? gcd(b, a % b) : a;
}
static void redirec... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
while (t--) {
long long n, m;
cin >> n >> m;
if (n == 1) {
cout << "0\n";
} else if (n == 2) {
cout << m << endl;
} else {
cout << 2 * m << endl;
}
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long s;
int main() {
int n;
cin >> n;
for (int i = 1; i < n; i++) {
long long a;
cin >> a;
s += a;
}
long long t = n;
t *= (n + 1);
t /= 2;
cout << t - s << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7, MN = 3e3 + 10;
string s[MN];
int dp[2][MN][MN];
int n, m;
int main() {
ios_base ::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; ++i) cin >> s[i], s[i] = '#' + s[i];
dp[0][1][2] = s[1][2] == '.', dp[1... | 17 |
#include <bits/stdc++.h>
using namespace std;
multiset<pair<int, int> > r, l;
int n, ans;
int a[100010], b[100010], v[100010];
int p1[100010], p2[100010];
int main() {
while (cin >> n) {
for (int i = 0; i < n; ++i) {
cin >> a[i];
p1[a[i]] = i;
}
for (int i = 0; i < n; ++i) {
cin >> b[i];... | 13 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int n, k;
cin >> n >> k;
string s;
cin >> s;
unordered_set<char> set;
char c;
while (k--) {
cin >> c;
set.insert(c);
}
ll answer = 0;
ll curr = 0;
for (int i = 0; i < s.length(); i++) {
if (set.find(s[i]) ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 51;
int pref[N][N], dp[N][N][N][N];
int get(int x, int y, int xx, int yy) {
return pref[xx][yy] - pref[x - 1][yy] - pref[xx][y - 1] + pref[x - 1][y - 1];
}
int calc(int x, int y, int xx, int yy) {
if (x > xx || y > yy || get(x, y, xx, yy) == 0) {
retur... | 15 |
#include <bits/stdc++.h>
using namespace std;
int x;
int arr[100], ans;
int main() {
scanf("%d", &x);
for (int i = 1; i <= 21; i += 2) {
arr[i] = (i * i + 1) / 2;
}
if (x == 3)
ans = 5;
else
for (int i = 1; i <= 21; i++) {
if (arr[i] >= x) {
ans = i;
break;
}
}
pr... | 9 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool vmin(T& a, T b) {
return (a > b) ? (a = b, true) : (false);
}
template <typename T>
bool vmax(T& a, T b) {
return (a < b) ? (a = b, true) : (false);
}
template <typename T>
T smax(T x) {
return x;
}
template <typename T, typename... K>
T sma... | 13 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int, int>>> v(27);
long long fastpow(long long b, long long p) {
if (!p) return 1;
long long ret = fastpow(b, p >> 1);
ret *= ret;
if (p & 1) ret *= b;
return ret;
}
long long dist(int x1, int x2, int y1, int y2) {
return fastpow(x1 - x2, 2) +... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, m, ans, fa[6];
char s[N], t[N];
bool e[6][6];
int find(int u) { return fa[u] == u ? u : fa[u] = find(fa[u]); }
int main() {
scanf("%s", s + 1);
scanf("%s", t + 1);
n = strlen(s + 1);
m = strlen(t + 1);
for (int i = 1, ans; i + m - 1 <... | 14 |
#include <bits/stdc++.h>
const int maxn = 5e5 + 7;
int pos[maxn << 1], n, m;
int dp[maxn << 1], flag;
bool check(int mid) {
for (int k = 1; k <= 2; k++) {
if (k == 1)
dp[k] = 0;
else
dp[k] = std::max(mid, pos[2]);
for (int i = k + 1; i <= n; i++) {
dp[i] = dp[i - 1];
if (dp[i - 1] ... | 25 |
#include <bits/stdc++.h>
using namespace std;
map<char, int> carr;
string str[1002];
int arr[1002];
int main() {
int n, m, cnt = 0;
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> str[i];
for (int i = 0; i < m; i++) cin >> arr[i];
for (int i = 0; i < m; i++) {
int mx = -1;
for (int j = 0; j < n; j++... | 1 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void printQueue(T& q) {
while (!q.empty()) {
cout << q.top() << endl;
q.pop();
}
}
long long power(long long a, long long b) {
long long r = 1;
while (b != 0) {
if (b % 2 != 0) {
r = r * a;
}
a = a * a;
b = b / 2;
}... | 2 |
#include <bits/stdc++.h>
using namespace std;
int color[1024][1024];
int main() {
int n, m, k;
cin >> n >> m >> k;
for (int i = 1; i <= k; i++) {
int x, y;
scanf("%d %d", &x, &y);
if (color[x - 1][y - 1] && color[x][y - 1] && color[x - 1][y]) {
printf("%d\n", i);
exit(0);
}
if (col... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
char t[20];
char ans[1050];
int main() {
int n;
scanf("%d", &n);
int curx = n, cury = n;
for (int i = n * 2 - 1; i >= n + 1; --i) {
printf("? %d %d %d %d\n", 1, 1, curx - 1, cury);
fflush(stdout);
scanf("%s", t);
if (t[... | 13 |
#include <bits/stdc++.h>
using namespace std;
struct Edge {
int to, cost, flow, cap, ind;
Edge* ret;
Edge() {}
Edge(int to, int cap, int cost, int ind)
: to(to), cap(cap), cost(cost), ind(ind), flow(0) {}
};
const int MX = 405, inf = 2000000;
int n1, n2, m, r, b, off, dis[MX], vis[MX], p[MX];
Edge* from[M... | 21 |
#include <bits/stdc++.h>
using namespace std;
int n, L, a, st[100005], l[100005], ans;
int main() {
scanf("%d%d%d", &n, &L, &a);
for (int i = 1; i <= n; i++) {
scanf("%d%d", &st[i], &l[i]);
}
st[n + 1] = L;
for (int i = 1; i <= n + 1; i++) {
int last = st[i] - (st[i - 1] + l[i - 1]);
ans += last /... | 2 |
#include <bits/stdc++.h>
using namespace std;
class _type {
public:
int t, x;
_type() {}
_type(int _t, int _x) {
t = _t;
x = _x;
}
};
int ans[200][200];
vector<_type> V;
void Shifting(int n, int m, int r, int c, int v) {
for (int i = V.size() - 1; i >= 0; i--) {
if (V[i].t == 1) {
if (V[i].... | 6 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-5;
const double INF = 1e+20;
int n;
double r, ans = INF;
struct point {
double x, y, z;
point() {}
point(double a, double b, double c) {
x = a;
y = b;
z = c;
}
void init() { scanf("%lf%lf%lf", &x, &y, &z); }
point operator-(cons... | 17 |
#include <bits/stdc++.h>
using namespace std;
void setw(int i, vector<vector<int>> &g, vector<int> &w) {
for (int j = 0; j < g[i].size(); j++) {
if (w[g[i][j]] == 0) {
w[g[i][j]] = 1;
setw(g[i][j], g, w);
}
}
}
bool check(vector<int> &v1, vector<int> &v2, vector<int> &w) {
for (int i = 0; i < ... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long fact(long long j) {
long long a = 1;
for (long long i = 1; i <= j; i++) a *= i;
return a;
}
long long sum2(long long c) {
long long s = 0;
while (c != 0) {
s += (c % 10) ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, s;
cin >> n >> s;
if (2 * n > s) {
cout << "NO\n";
} else {
cout << "YES\n";
for (int i = 0; i < (n - 1); i++) {
cout << 2 << " ";
}
cout << (s)-2 * (n - 1) << "\n";
cout << 1 << "\n";
}
return 0;
}
| 6 |
#include <bits/stdc++.h>
using namespace std;
int x[100005], y[100005], nxt[100005];
int bit[100005], ans[100005];
vector<int> bucket[100005];
int main() {
int N;
cin >> N;
for (int i = 1; i <= N; i++) {
cin >> x[i];
y[i] = N + 1;
}
for (int i = N; i >= 1; i--) {
nxt[i] = y[x[i]];
y[x[i]] = i;... | 16 |
#include <bits/stdc++.h>
using namespace std;
const double pi = 3.14159265358979323846;
void cp() {}
void solve() {
long long n;
cin >> n;
long long count = 0, c = 0;
while (n % 3 == 0) {
n /= 3;
c++;
count++;
}
count += c;
c = 0;
while (n % 5 == 0) {
n /= 5;
c++;
count += 2;
}... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long LINF = 1e18;
int A[200003];
void solve() {
int n;
cin >> n;
string s;
cin >> s;
int sz = 0, cnt = 0;
queue<int> q1, q2;
for (int i = 0; i < n; i++) {
++cnt;
if (i + 1 == n || s[i + 1] != s[i]) {
q1.push(sz);
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int inf = (1 << 30) - 1;
const long long linf = (1ll << 62) - 1;
const int C = 3001;
int main() {
int n;
cin >> n;
vector<pair<pair<int, int>, int>> points(n);
for (int i = 0; i < n; i++) {
scanf("%d%d", &points[i].first.first, &points[i].first.second);
... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n, x, u, fail[300005], k, nx[300005][30], ans;
string p[300005], s;
vector<int> v[300005];
void solve(int node = 1, int pos = 0) {
for (auto i : v[node]) {
int hop = pos;
for (int j = 0; j < (int)p[i].size(); j++) {
hop = nx[hop][p[i][j] - 'a'];
if... | 12 |
#include <bits/stdc++.h>
using namespace std;
int m, k;
int d[1005], s[1005];
int main() {
int sum, maxs = 0;
while (cin >> m >> k) {
sum = 0;
for (int i = 0; i < m; i++) {
cin >> d[i];
sum += d[i];
}
for (int i = 0; i < m; i++) cin >> s[i];
int ss = 0;
for (int i = 0; i < m; i++... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
if (n > 1)
cout << n << " " << n + 1 << " " << n * (n + 1) << "\n";
else
cout << "-1\n";
return 0;
}
| 7 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1 * 1e5 + 17;
pair<int, int> first[5];
pair<int, int> second[5];
pair<int, int> vec(pair<int, int> x, pair<int, int> y) {
return {y.first - x.first, y.second - x.second};
}
int dot(pair<int, int> x, pair<int, int> y) {
return x.first * y.first + x.secon... | 8 |
#include <bits/stdc++.h>
using namespace std;
struct _in {
inline operator char() {
char c = getchar_unlocked();
getchar_unlocked();
return c;
}
inline operator double() {
double d;
scanf("%lf", &d);
getchar_unlocked();
return d;
}
template <typename T>
inline operator T() {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
short int min_b = 1024;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int n, m;
cin >> n >> m;
vector<short int> a(n), b(m);
min_b = 1024;
for (long long int i = 0; i < n; i++) cin >> a[i];
for (long long int i = 0... | 8 |
#include <bits/stdc++.h>
using namespace std;
static const double EPS = 1e-6;
inline int ROUND(double x) { return (int)(x + 0.5); }
inline bool ISINT(double x) { return fabs(ROUND(x) - x) < EPS; }
inline bool ISEQUAL(double x, double y) {
return fabs(x - y) <= EPS * max(fabs(x), fabs(y));
}
int main() {
int a1, a2,... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3001;
const long long inf = 1e18;
pair<long long, long long> dp[N][N], inner[N];
int n, m;
vector<int> g[N];
int a[N];
int sub[N];
pair<long long, long long> Merge(pair<long long, long long> a,
pair<long long, long long> b) {
... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int s;
char cc;
string name[100];
char c[6];
int num[100][3];
bool f, f1, f2;
int max1, max2, max3;
cin >> n;
for (int i = 0; i < n; i++) {
num[i][0] = 0;
num[i][1] = 0;
num[i][2] = 0;
}
for (int i = 0; i < n; i++) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
};
int n, i, j, a, b;
cin >> n;
vector<pair<int, int>> v;
for (i = 0; i < n; i++) {
cin >> a >> b;
v.push_back({a, b});
}
long double dp[n + 1][n + 1];
for (i = 0; i <= n; ... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
while (b) b ^= a ^= b ^= a %= b;
return a;
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
long long bigmod(long long b, long long p, long long m) {
long long ans = 1;
b %= m;
if (!b) return 0;
wh... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e3 + 5;
const int mod = 1e9 + 9;
int a[105][105];
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (a[i][j] == 0) {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
namespace NTT {
const int EXP = 23;
const unsigned long long EXP_MULT = 119, NTT_MOD = (EXP_MULT << EXP) + 1;
unsigned long long rt[EXP + 1], invrt[EXP + 1];
bool built;
unsigned long long modPow(unsigned long long a, unsigned long long p) {
return p ? modPow((a) * (a) % ... | 21 |
#include <bits/stdc++.h>
using namespace std;
int cuo[] = {1, 0, 1, 2, 9};
long long C[1100][5];
void init() {
C[0][0] = 1;
for (int i = 1; i <= 1000; i++) {
C[i][0] = 1;
for (int j = 1; j <= i && j <= 4; j++)
C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
}
}
int main() {
int n, k;
init();
while (s... | 8 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll dp[1000][1000];
ll st[1000];
ll ist[1000];
ll mp[1000][1000];
const ll mod = 998244353;
ll choose(ll a, ll j) {
if (j == 0 || j == a) return 1;
return st[a] * ist[j] % mod * ist[a - j] % mod;
}
ll mpow(ll a, ll j) {
if (j == 0) return 1;
ll ... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, cnt = 0;
cin >> n;
long long nechpr = 0, chpr = 0, nechsuf = 0, chsuf = 0;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
if (i % 2 == 0) {
chsuf += a[i];
} else {
nechsuf += a[i];
}
}
for (int i = ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int n, a[2][maxn];
class Graph {
private:
int n;
vector<vector<pair<int, int>>> adj;
int colorSet[2];
bool dfs(int u, int color, vector<int>& c) {
if (c[u] != -1) return c[u] == colorSet[color];
c[u] = colorSet[color];
for (au... | 15 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
long long t;
cin >> t;
while (t--) {
long long n, n1, a;
cin >> n;
set<long long> s;
n1 = n;
if (n > 1000000) {
n1 = 1000000;
a = n / pow(10, 6);
for (long long i = 1; i < a... | 6 |
#include <bits/stdc++.h>
using namespace std;
void maxi() {
long long n, l, r = INT64_MIN;
cin >> n >> l;
long long a[n];
for (long long i = 0; i < n; i++) {
cin >> a[i];
if (a[i] > r) {
r = a[i];
}
}
long long ans = 0;
for (long long i = l; i <= r; i++) {
long long k = 0;
for (l... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int m, n, i, j;
char a[1001][1001];
long long int hor[1001];
long long int ver[1001];
long long int count = 0;
long long int val;
scanf("%d%d", &m, &n);
getchar();
for (i = 0; i < m; i++) {
count = 0;
for (j = 0; j < n; j++) {
sc... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int WASHING_FINISHED = 2;
const int DRYING_FINISHED = 1;
const int FOLDING_FINISHED = 0;
int k;
int n1, n2, n3;
int t1, t2, t3;
struct State {
int raw;
int washing;
int drying;
int folding;
int washed;
int dried;
int folded;
State(int r, int w, int d, ... | 11 |
#include <bits/stdc++.h>
#pragma GCC optimize( \
"Ofast,no-stack-protector,unroll-loops,no-stack-protector,fast-math")
using namespace std;
const int N = 2e5 + 5, M = 1e6 + 5;
long long n;
string s = "codeforces";
int main() {
scanf("%lld", &n);
long long lst = 1;
for (int i = 1;; ++i) {
long long pro = 1... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long power_modulo(long long base, long long exp, long long mod) {
long long result = 1;
base %= mod;
while (exp > 0) {
if (exp % 2 == 1) result = (result * base) % mod;
exp = exp >> 1;
base = (base * base) % mod;
}
return result;
}
int main() {
... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long i, j, n, k, k1, k2, k3, m, h, z, l, x, y, r;
long long dp[1005][1005];
string s;
long long fib[600500];
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, j, k;
string s;
cin >> n >> s;
char i;
int vis[200001];
for (i = '0'; i <= '9'; i++) {
bool ok1 = 0, ok2 = 0;
memset(vis, 0, n * sizeof(int));
string s1 = "", s2 = "", ans, te... | 7 |
#include <bits/stdc++.h>
using namespace std;
bool is_prime(int x) {
for (int i = 2; i * i <= x; i++)
if (x % i == 0) return false;
return true;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
if (is_prime(n)) {
cout << n << " " << 0;
return 0;
}
vector<pair<int, i... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long a, r, b, k, s, c, t, j, v, i, l, low, high, n, w, h, d[1111], m[1000];
pair<long long, long long> x[11111];
string q[100000], p;
char e;
int main() {
cin >> n;
for (i = 0; i < n * n; i++) {
cin >> a >> b;
if (d[a] + m[b] == 0) {
cout << i + 1 << ... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long pw(long long b, long long r) {
long long ans = 1;
while (r) {
if (r & 1) ans = (ans * b) % 1000000007;
b = (b * b) % 1000000007;
r >>= 1;
}
return ans;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
long long a, b, as, bs, tmp(n + 1);
for (int i = 1; i <= n; i++) {
if (n % i == 0) {
a = i;
b = n / i;
if (abs(a - b) < tmp) {
as = a;
bs = b;
tmp = abs(a - b);
}
}
}
cou... | 0 |
#include <bits/stdc++.h>
using namespace std;
int col[300010], flag[300010];
vector<int> ice[300010];
vector<int> edge[300010];
int dfn;
void dfs(int u, int f) {
for (int ic : ice[u]) {
if (col[ic]) {
flag[col[ic]] = dfn;
}
}
int cur = 1;
for (int ic : ice[u]) {
if (!col[ic]) {
while (fl... | 14 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void pv(T a, T b) {
for (T i = a; i != b; ++i) cout << *i << " ";
cout << endl;
}
template <class T>
void pvp(T a, T b) {
for (T i = a; i != b; ++i)
cout << "(" << i->first << ", " << i->second << ") ";
cout << endl;
}
void chmin(int &t, int f... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n, m, now = -1, cnt, xx, yy, tmpa, tmpb, nowtmp;
int head[100009], a[100009], b[100009], q[100009 * 2], ex[2][100009], ans[2],
vis[100009];
bool can, iv[2][100009];
char cc;
struct edge {
int next, to, w;
};
edge e[100009 * 2];
int read() {
int x = 0;
char ch ... | 14 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long t;
cin >> t;
long long mi = 1, csk = 0;
while (t--) {
long long n;
cin >> n;
string s;
cin >> s;
long long odd = 0;
long long even = 0;
if (n & 1) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long n;
cin >> n;
long long a[n];
for (long long i = 0; i < n; ++i) {
cin >> a[i];
}
sort(a, a + n);
long long ans = 0;
long long j = n - 1;
while (j >= 3) {
long lo... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int MAX = 200005;
char str[MAX];
scanf("%s", str);
int n = strlen(str);
int i, k;
if (n == 1)
printf("%s\n", str);
else {
string ans = "";
i = 0;
ans = ans + str[0] + str[1];
for (i = 2; i < n; i++) {
char ch = str[i];
... | 6 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.