solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
const int MAX_LOG_V = 20;
struct Edge {
int v, id;
Edge(int _v, int _id) : v(_v), id(_id) {}
};
vector<Edge> edges[MAXN];
int parent[MAX_LOG_V][MAXN], depth[MAXN];
int ans[MAXN], cnt[MAXN];
void dfs(int u, int father) {
parent[0][u] = father;
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n], dp[n], dp1[n], cm = 1;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
dp[0] = 1;
for (int i = 1; i < n; i++) {
if (a[i] > a[i - 1]) {
dp[i] = dp[i - 1] + 1;
} else {
dp[i] = 1;
}
}
dp1[n - 1... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int Mn = 1e5 + 5;
struct A {
long long a;
bool x;
} p[Mn << 1];
int cnt = 0;
bool cmp(A a, A b) {
if (a.a != b.a) return a.a < b.a;
return a.x < b.x;
}
int main() {
int n;
scanf("%d", &n);
long long x, y;
for (int i = 1; i <= n; i++) {
scanf("%lld%... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int main() {
int n, m, p, a1, a2;
scanf("%d%d%d", &n, &m, &p);
for (int i = 0; i < n; i++) {
int x;
scanf("%d", &x);
if (x % p) a1 = i;
}
for (int i = 0; i < m; i++) {
int x;
scanf("%d", &x);
if (x % p) a2 = i;
}
cou... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x;
int total;
int div, mod;
vector<int> V;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x;
V.push_back(x);
}
sort(V.begin(), V.end());
total = accumulate(V.begin(), V.end(), 0);
div = total / n, mod = total % n;
vector<int... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, t;
cin >> s >> t;
int j = 1;
for (int i = 0, n = t.length(); i < n; i++) {
if (t[i] == s[j - 1]) {
if (j < s.length()) j++;
}
}
cout << j;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 7;
int f[MAXN], n, cnt[MAXN], ans;
bool mrk[MAXN];
string s;
void prep() {
int k = 0;
for (int i = 1; i < n; i++) {
while (k && s[i] != s[k]) k = f[k];
k += (s[i] == s[k]);
f[i + 1] = k;
}
}
int32_t main() {
cin >> s;
n = s.size(... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
long long int t;
cin >> t;
while (t--) {
long long int n;
cin >> n;
string str;
cin >> str;
int first = -1, l = -1;
for (long long int i = 0; i < n; i++) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int solve() {
int n;
cin >> n;
string s, t;
cin >> s >> t;
string p = s, q = t;
sort(p.begin(), p.end());
sort(q.begin(), q.end());
if (p != q) return -1;
int ans = INT16_MAX;
for (int i = 0; i < n; i++) {
int k = i;
for (int j = 0; j < n; j++)
... | 14 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
string s;
cin >> s;
int ans = n;
for (int i = 0; i < n - 1; i++) {
string check = s.substr(i, 2);
if (check == "RU" || check == "UR") {
ans -= 1;
i++;
}
}
cout << ans << "\n";
}
int main() {
ios_base:... | 0 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int ch[26];
int par, val;
long long w;
node(int val = 0) : par(0), val(val) {
memset(ch, 0, sizeof(ch));
w = 0;
}
};
node sam[1000005];
char st[500005];
int val[100005];
int ed[100005];
int b[1000005];
int h[500005];
int n, m, c, last;
void a... | 19 |
#include <bits/stdc++.h>
using namespace std;
bool checkok(const string& s) {
if (s == "") return false;
if (s == "0") return true;
if (s[0] == '0') return false;
return true;
}
string r(const string& s, int i) {
return (i ? s.substr(0, i) : "") +
(i + 1 < s.length() ? s.substr(i + 1) : "");
}
void e... | 12 |
#include <bits/stdc++.h>
using namespace std;
int girl[100 + 1] = {0}, taxi[100 + 1] = {0}, pizza[100 + 1] = {0};
string name[100 + 1];
int main() {
int n, m, i, j, max;
string s;
vector<string> ans;
cin >> n;
for (i = 0; i < n; i++) {
cin >> m >> name[i];
for (j = 0; j < m; j++) {
cin >> s;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int size1 = 4e5;
const int INF = 2e9;
const long long mod = 1e9 + 7;
int main() {
int n, i;
cin >> n;
long long deg = 1, deg1 = 1;
for (i = 1; i <= n; i++) {
deg = (deg * 27) % mod;
deg1 = (deg1 * 7) % mod;
}
cout << ((deg - deg1) % mod + mod) % mo... | 7 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using i2 = pair<int, int>;
using ll2 = pair<ll, ll>;
const int N = 3e5 + 9;
const ll inf = 1e18;
ll A[N], dp[N][2];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int T;
cin >> T;
while (T--) {
int n, q;
cin >> n >> q;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n, m;
ll l, r;
vector<int> factor[200005];
ll facSum[200005];
int main() {
cin >> n >> m >> l >> r;
int bound = max(n, m);
for (int i = 1; i <= bound; ++i) {
for (int j = i; j <= bound; j += i) {
factor[j].push_back(i);
}
}
... | 22 |
#include <bits/stdc++.h>
using namespace std;
inline int getidx(const vector<int>& ar, int x) {
lower_bound(ar.begin(), ar.end(), x) - ar.begin();
}
inline long long GCD(long long a, long long b) {
long long n;
if (a < b) swap(a, b);
while (b != 0) {
n = a % b;
a = b;
b = n;
}
return a;
}
inline... | 13 |
#include <bits/stdc++.h>
using namespace std;
string s[] = {"OTHER", "CHECKMATE"};
int dx[] = {0, 1, 0, -1, -1, -1, 1, 1};
int dy[] = {1, 0, -1, 0, -1, 1, -1, 1};
int a[5], b[5];
int board[20][20];
bool in(int x, int y) { return x >= 1 && x <= 8 && y >= 1 && y <= 8; }
void read(int& xx, int& yy) {
char x, y;
cin >>... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long infl = 1e18 + 5;
long long n, m, k, q, x, y, f, val, t, i, j;
long long ind, cnt, sz, sm, ans, mx, mn;
long long vis[1000004];
long long dp[1000004][2];
vector<long long> g[1000004], v;
int dfs(int u, int p) {
if (vis[u] == 2) f = 1;
if (dp[u][p] != -1) ... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int n;
long long d[205][205];
struct point {
long long x, y;
long long operator*(const point &b) const { return x * b.y - y * b.x; }
point operator-(const point &b) const { return point{x - b.x, y - b.y}; }
} p[205];
long long solve(int l, int... | 17 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 80, T = 3, INF = 1e9;
string s;
long long n;
struct occ {
long long a[T];
long long &operator[](long long i) { return a[i]; }
};
bool operator==(occ a, occ b) {
for (long long t = 0; t < (long long)(T); t++)
if (a[t] != b[t]) return false;
re... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int m;
cin >> m;
int s[10002];
s[0] = 0;
for (int i = 0; i < m; i++) {
int c;
cin >> c;
s[i + 1] = s[i] + c;
}
int x, y;
cin >> x >> y;
int answer = 0;
for (int i = 1; i <= m; i++) {
int low = s[i - 1];
int high = s[m] - ... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void upd1(T& a, T b) {
a > b ? a = b : 0;
}
template <class T>
inline void upd2(T& a, T b) {
a < b ? a = b : 0;
}
struct ano {
operator long long() {
long long x = 0, y = 0, c = getchar();
while (c < 48) y = c == 45, c = getchar();
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 333333;
const long long MOD = 998244353LL;
long long addmod(long long x, long long y) {
x += y;
if (x >= MOD) x -= MOD;
return x;
}
int headp[N], nextp[N], to[N];
inline void addedge(int x, int y, int &tot) {
to[tot] = y;
nextp[tot] = headp[x];
hea... | 17 |
#include <bits/stdc++.h>
using namespace std;
long long dp[200010], ans;
int main() {
int n, m, a[200010];
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
sort(a + 1, a + n + 1);
for (int k = 1; k <= n; k++) {
if (k <= m) {
dp[k] = a[k];
} else
dp[k] = a[k] + dp[k - m];
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int N = 400000;
vector<int> p(2 * N - 1);
int summa(int a, int b) {
a += N;
b += N;
int s = 0;
while (a <= b) {
if (a % 2 == 1) s += p[a++];
if (b % 2 == 0) s += p[b--];
a /= 2;
b /= 2;
}
return s;
}
void lisaa(int k, int x) {
k += N;
p[k] +=... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1010;
int n, m;
char s[MAXN][MAXN];
void finish() {
puts("-1");
exit(0);
}
int bio[MAXN][MAXN];
const int smjerx[] = {1, 0, -1, 0};
const int smjery[] = {0, -1, 0, 1};
void dfs(int x, int y) {
bio[x][y] = 1;
for (int i = (0); i < int(4); i++) {
... | 12 |
#include <bits/stdc++.h>
using namespace std;
const long long int infinity = 9e18;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
for (int idx = 0; idx < t; idx++) {
long long int n;
cin >> n;
vector<long long int> v(n);
map<long long int, long long int> m;
... | 10 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
if(n % 2 == 0){
for(int i = 2; i <= n; i += 2){
cout<<i<<" "<<i - 1<<" ";
}
cout<<"\n";
}else{
for(int i = 2; ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
pair<int, pair<int, pair<int, pair<int, int> > > > arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i].first >> arr[i].second.first >> arr[i].second.second.first >>
arr[i].second.second.second.first;
arr[i].second.second... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long n, l, r, i, j, a[50][5], k, used[1228228];
double bits[21][1228228];
vector<long long> f[2];
double dist(double x1, double y1, double x2, double y2) {
return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
double find_some_shit(double l, double alpha, dou... | 14 |
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
const long double EPS = 0.0000000001;
const long long INF = 1000000007;
using namespace std;
int main() {
int n, x, m = 0, ans = 0;
cin >> n;
for (int i = 0; i < n; i++) {
int q;
cin >> q;
m = max(q, m);
if (i == n - 1) x = q;
}
x ^= m;
... | 10 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n, m;
vector<string> table;
const vector<int> dx = {-1, -1, -1, 0, 0, 1, 1, 1};
const vector<int> dy = {-1, 0, 1, -1, 1, -1, 0, 1};
bool ok(int x, int y) { return 0 <= x && x < n && 0 <= y && y < m; }
pair<bool, vector<string>> get(int T) {
queue... | 14 |
#include <bits/stdc++.h>
using namespace std;
vector<int> prime;
bool notprime[1000001] = {0};
const int N = 78497;
int main() {
for (int i = 2; i <= 1000000; i++) {
if (!notprime[i]) {
prime.push_back(i);
for (int j = 2 * i; j <= 1000000; j += i) notprime[j] = true;
}
}
int x;
cin >> x;
i... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int a, b;
cin >> a >> b;
if (a == 0 && b == 0)
cout << "NO";
else if (a == (b + 1))
cout << "YES";
else if (b == (a + 1) || a == b)
cout << "YES";
else
cout << "NO";
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 2e14 + 1;
long long n, m, pp = 0;
map<long long, long long, greater<long long>> x;
vector<int> v;
vector<long long> q;
bool first(long long mi, long long sk) {
long long cur = 0, skip = 0;
priority_queue<int, vector<int>, greater<int>> active;
fo... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2050;
const int dx[] = {1, 0, 0, -1};
const int dy[] = {0, -1, 1, 0};
const char stp[] = {'D', 'L', 'R', 'U'};
char s[N][N];
bool flag;
int n, m, k, dis[N][N], sx, sy, q[20000050][2];
bool is(int nx, int ny) {
return ((nx > 0 && nx <= n && ny > 0 && ny <= m)... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 100;
long long dp[maxn][maxn];
void O__O() {
for (long long i = 0; i < 100; i++) {
for (long long j = 0; j < 100; j++) {
if (j == 1) {
dp[i][j] = i;
} else if (i == 0 || j == 0) {
dp[i][j] = 1;
} else if (i == j... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long read() {
long long a = 0, fh = 1;
char c = getchar();
while (c > '9' || c < '0') {
if (c == '-') fh = -1;
c = getchar();
}
while ('0' <= c && c <= '9') {
a = a * 10 + c - 48;
c = getchar();
}
return a * fh;
}
long long n, m, q, X[1000... | 22 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
int read() {
char c;
int ans = 0, f = 1;
c = getchar();
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
ans = ans * 10 + c - '0';
c = getchar... | 14 |
#include <bits/stdc++.h>
using namespace std;
inline char gc() {
static char buf[100000], *p1 = buf, *p2 = buf;
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
? EOF
: *p1++;
}
inline long long read() {
long long x = 0;
char ch = getchar();
bool positive... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fll;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
string s;
cin >> s;
string ans = s;
for (int i = 0; i < n; i++) {
string cur = s;
int shift = cur[0] - '0... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
double ans = -1.0;
int x[4], y[4];
void check(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3,
bool s) {
int tx[4] = {x0, x1, x2, x3};
int ty[4] = {y0, y1, y2, y3};
for (int i = 0; i < (int)(4); i++)
for (int j = 0; j < (int)(i)... | 10 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int res = 0, f = 1;
char ch;
while (ch = getchar(), ch < '0' || ch > '9')
if (ch == '-') f = -1;
while (ch >= '0' && ch <= '9') res = res * 10 + ch - '0', ch = getchar();
return res * f;
}
const int N = 2e5 + 5, INF = 0x3f3f3f3f;
const long... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, sum = 0, c = 0, cnt = 0, sumf = 0, j = 0;
cin >> n;
int a[n], b[n];
cin >> a[0];
b[0] = a[0];
for (int i = 1; i < n; i++) {
cin >> a[i];
b[i] = a[i];
if (a[i] == a[i - 1]) {
cnt++;
}
sum = sum + a[i];
}
if (cnt =... | 2 |
#include <bits/stdc++.h>
using namespace std;
struct point {
double x, y;
point(double x, double y) : x(x), y(y) {}
point() { x = y = 0.0; }
point operator+(point q) { return point(x + q.x, y + q.y); }
point operator-(point q) { return point(x - q.x, y - q.y); }
point operator*(double t) { return point(x * ... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
long long int header[100007], track[100007];
int check(long long int Time) {
int mark[100007];
memset(mark, 0, sizeof mark);
int trackpos = 1;
for (int i = 1; i <= n; i++) {
if (trackpos > m) break;
if (track[trackpos] <= header[i]) {
long lo... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int Z = (int)1e5 + 111;
const int inf = (int)1e9 + 111;
const long long llinf = (long long)1e18 + 5;
const int MOD = (int)1e9 + 7;
int used[Z], f1[Z], f2[Z], p[Z], b[Z], ans[Z], n;
bool ok(int x) {
for (int i = 0; i < n; ++i) {
used[i] = -1;
}
for (int i = 0... | 12 |
#include <bits/stdc++.h>
using namespace std;
int v[111][111];
int n, m;
int vis[111][111];
long long fun(int i, int j) {
int ii = n - i - 1;
int jj = m - j - 1;
vector<int> e;
e.push_back(v[i][j]);
vis[i][j] = 1;
if (!vis[i][jj]) {
e.push_back(v[i][jj]);
vis[i][jj] = 1;
}
if (!vis[ii][j]) {
... | 5 |
#include <bits/stdc++.h>
int main() {
int n, a, x;
scanf("%d", &n);
a = n / 3;
if (n % 3 == 2) a = a + 1;
x = a / 12;
a = a % 12;
printf("%d %d", x, a);
return 0;
}
| 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int n = s.length();
for (int i = 0; i < n; i++) cout << s[i];
for (int i = n - 1; i >= 0; i--) cout << s[i];
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const long long maxn = 3e6;
const long long mod = 1e9 + 7;
const long double PI = acos((long double)-1);
long long pw(long long a, long long b, long long md = mod) {
long long res = 1;
while (b) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
enum { maxn = 1000010, mod = 1000000007 };
int fac[maxn];
int A[maxn];
int Ak[maxn];
int inv[maxn];
int power(int base, int times) {
int ans = 1;
for (; times; times >>= 1) {
if (times & 1) {
ans = (long long)ans * base % mod;
}
base = (long long)base ... | 22 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, a, q, p;
long long pa[1048576];
long long ans[1048576];
long long inv[1048576];
pair<int, int> egcd(int a, int b) {
if (a == 0) return pair<int, int>(0, 1);
pair<int, int> temp = egcd(b % a, a);
return pair<int, int>((temp.second - b / a * temp.first) ... | 14 |
#include <bits/stdc++.h>
long long M = 1000000007;
using namespace std;
bool prime(long long n) {
if (n < 2) return false;
for (int x = 2; x * x <= n; x++) {
if (n % x == 0) return false;
}
return true;
}
int main() {
long long n, h, k;
long long s = 0, x, c = 0;
cin >> n >> h >> k;
for (long long i... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, a, b, c, cost;
cin >> n >> a >> b >> c;
long long k = 4 - (n % 4);
if (n % 4 == 0)
cout << "0\n";
else if (k == 1) {
long long cost_a = a;
long long cost_b = b + c;
long long cost_c = 3 * c;
cout << min(min(cost_a, cos... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long int power(long long int a, long long int b) {
long long int ans = 1;
while (b) {
if (b & 1LL) ans = (ans * a) % 1000000007;
a = (a * a) % 1000000007;
b = b >> 1LL;
}
return ans;
}
long long int t, n, p, k;
long long int a[2 * 100005];
pair<long... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, c = 0, k = 0;
string s;
map<char, int> m;
int main() {
cin >> n >> s;
for (int i = 0; i < n && c <= 26; i++) {
if (m[s[i]] == 0) c++;
m[s[i]]++;
if (m[s[i]] > 1) k++;
}
if (26 - c >= k)
cout << k << endl;
else
cout << -1 << endl;
retur... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, y, a, b, c, d;
cin >> a >> b >> c >> d;
x = max((float(3 * a) / float(10)), a - (float(a) / float(250)) * c);
y = max((float(3 * b) / float(10)), b - (float(b) / float(250)) * d);
if (x > y)
cout << "Misha";
else if (x < y)
cout << "V... | 1 |
#include <bits/stdc++.h>
using namespace std;
pair<int, long long> arr[300010];
int main(void) {
int N;
cin >> N;
long long sum = 0;
long long ans = 0;
for (int i = 0; i < N; i++) cin >> arr[i].first >> arr[i].second;
for (int i = 0; i < N; i++) sum += arr[i].first;
if (sum > 0) {
for (int i = 0; i < ... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> v;
if (m % 2 != 0) {
v.push_back((m + 1) / 2);
for (int i = 1; i < (m + 1) / 2; i++) {
v.push_back((m + 1) / 2 - i);
v.push_back((m + 1) / 2 + i);
}
} else {
for (int i = 0; i < m / 2; i... | 5 |
//To debug : g++ -g file.cpp -o code
//to flush output : fflush(stdout) or cout.flush()
//cout<<setprecision(p)<<fixed<<var
//use 1LL<<i to for 64 bit shifting , (ll)2 because by default 2 is ll
//take care of precedence rule of operators
//do not forget to change the sizes of arrays and value of contants and other t... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long multiply(long long a, long long b) {
return ((a % mod) * (b % mod)) % mod;
}
long long add(long long a, long long b) {
return ((a % mod) + (b % mod)) % mod;
}
long long sub(long long a, long long b) {
return ((a % mod) - (b % m... | 9 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
long long t;
cin >> t;
while (t--) {
long long k;
cin >> k;
long long i = 1;
for (i = 1; i * i <= k; i++) {
;
}
i--;
k -= i * i;
if (k == 0) {
cout << i << " " << 1 << endl;
} else if (k <= i + 1) {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int solve() {
long long n;
cin >> n;
for (long long i = 1; i <= n; i++) cout << i << " ";
cout << endl;
return 0;
}
int main() {
long long t;
cin >> t;
while (t--) solve();
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
struct point {
double x, y;
} p[111][3], A, B, C, D;
void prin(point A) { cout << A.x << " " << A.y << endl; }
double area(point a, point b, point c) {
return (((b.x - a.x) * (c.y - a.y)) - ((c.x - a.x) * (b.y - a.y))) / 2;
}
int ins(int tid, point po) {
double ret = ... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long long int a, b, c, k;
cin >> a >> b >> c;
k = a + b + c;
k = k / 2;
cout << k << endl;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long GCD(long long x, long long y) { return !y ? x : GCD(y, x % y); }
long long LCM(long long x, long long y) { return x * y / GCD(x, y); }
int arr1[100], arr2[100];
int main() {
ios::sync_with_stdio(false);
ios_base::sync_with_stdio(false);
cin.tie(nullptr), cou... | 3 |
#include <bits/stdc++.h>
using namespace std;
int Set(int N, int pos) { return N = N | (1 << pos); }
int reset(int N, int pos) { return N = N & ~(1 << pos); }
bool check(int N, int pos) { return (bool)(N & (1 << pos)); }
inline int addmod(int x, int y) {
return (x % 1000000007 + y % 1000000007) % 1000000007;
}
inline... | 7 |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define For(i,a,b,c) for(ll i=a;i<b;i+=c)
#define For2(i,a,b,c) for(ll i=a;i>=b;i-=c)
#define vec_ll vector<vector<ll>>
#define vec_pr vector<pair<ll,ll>>
#define p_ll pair<ll,ll>
#define pbk push_back
#define mkpr make_pair
#define fst first
#define snd... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long int binarySearch(long long int l, long long int r,
long long int value) {
if (l > r) return r;
long long int mid = l + (r - l) / 2,
val = ((3 * mid + 4) * (mid - 1)) / 2 + 2;
if (val <= value) return binarySearch(mi... | 3 |
#include <bits/stdc++.h>
using namespace std;
typedef struct node {
node *x[26];
node() {
for (int i = 0; i < 26; ++i) x[i] = NULL;
}
} node;
node *root;
void add(string s) {
node *temp = root;
int len = s.size();
for (int i = 0; i < len; ++i) {
if (temp->x[s[i] - 'a'] == NULL) {
temp->x[s[i] ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n;
char s[1000005];
bool check(int x) {
int p = 0, lst = 0;
bool flag = 1;
for (int i = 0; i < n; i++) {
if (s[i] == 'R') {
flag = 0;
if (p + 1 != x) p++;
} else
p--;
if (p < lst) {
lst = p;
flag = 1;
}
}
return fl... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int T, n, i, j;
string s, t;
scanf("%d", &T);
while (T--) {
int ans = 1e9 + 7, temp;
scanf("%d", &n);
cin >> s >> t;
for (i = 0; i < n; i++) {
temp = i;
for (j = 0; j < n; j++)
if (temp != n && t[temp] == s[j]) temp++... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100100;
pair<int, int> ar[MAXN];
bool vis[MAXN];
int N;
int ans = 0;
int X[2 * MAXN];
int Y[2 * MAXN];
void mv(int a, int b) {
X[ans] = a;
Y[ans] = b;
++ans;
}
bool lucky(int x) {
while (x) {
int dig = x % 10;
x /= 10;
if (dig != 4 && di... | 12 |
#include <bits/stdc++.h>
using namespace std;
vector<int> a(200005);
int n;
int k;
bool calc(int mx) {
int ok = k;
if (ok % 2 == 0) {
k = k / 2;
int ct = 0;
int ls = -3;
for (int i = 0; i < n; i++) {
if (i - ls >= 2 && a[i] <= mx) {
ls = i;
ct++;
if (i < n - 1 && ct >= ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> arr(m);
int sum = 0;
for (int i = 0; i < m; i++) {
cin >> arr[i];
if (sum < n) sum += arr[i];
if (arr[i] + i > n) {
printf("-1\n");
return 0;
}
}
if (sum < n) {
printf("-1\n");
... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long double pi = acosl(-1);
int n;
pair<long double, pair<long double, long double> > a, b;
void home() {}
void enter() {
long long x, y, z;
cin >> x >> y >> z;
a = {x, {y, z}};
cin >> x >> y >> z;
b = {x, {y, z}};
if (a.second.second > b.second.second) sw... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
vector<long long> v(n);
for (long long i = 0; i < n; i++) cin >> v[i];
vector<long long> positive;
vector<long long> negative;
for (long long i = 0; i < n; i++) {
if (v[i] > 0)
positive.push_back(v[i]);
else
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[1001000];
int x[3] = {0, -1, 1};
int main() {
scanf("%d", &n);
for (int i = 0; i != n; i++) {
scanf("%d", &a[i]);
}
int t1;
int t2;
bool suc = 0;
int minn = 0x7f7f7f7f;
for (int i = 0; i != 3; i++) {
t1 = a[0] + x[i];
int ans = 0;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long T, n, m, ans, i, p;
vector<int> v[200003];
int main() {
cin >> T;
while (T--) {
ans = 0;
cin >> n;
for (i = 0; i <= n; i++) v[i].clear();
priority_queue<int> q;
for (i = 0; i < n; i++) cin >> m >> p, v[m].push_back(p);
for (int i = n; i... | 16 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void dbs(string str, T t) {
cerr << str << " : " << t << "\n";
}
template <class T, class... S>
void dbs(string str, T t, S... s) {
int idx = str.find(',');
cerr << str.substr(0, idx) << " : " << t << ",";
dbs(str.substr(idx + 1), s...);
}
templat... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long int arr[1000001];
void sieve() {
long long int mx = 1000000;
for (long long int i = 1; i <= mx; i++) arr[i] = i;
for (long long int i = 2; i * i <= mx; i++) {
if (arr[i] == i) {
for (long long int j = i * i; j <= mx; j += i) {
if (arr[j] ==... | 3 |
#include <bits/stdc++.h>
using ll = long long;
const ll N = 2 * 1e5 + 5;
const ll mod = 1e9 + 7;
const ll inf = 1e18;
const ll SZ = 101;
const double eps = 1e-9;
using namespace std;
void solve() {
ll n, h, m;
cin >> n >> h >> m;
vector<ll> a(n, h);
for (ll(i) = 0; i < (m); i++) {
ll l, r, x;
cin >> l >... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 200050;
int N, a[MaxN], dp[MaxN];
int main() {
scanf("%d", &N);
for (int i = 1; i <= N; ++i) scanf("%d", &a[i]), a[i] += a[i - 1];
dp[N] = a[N];
for (int i = N - 1; i > 1; --i) dp[i] = max(dp[i + 1], a[i] - dp[i + 1]);
printf("%d", dp[2]);
retur... | 14 |
#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 9;
int m;
vector<pair<int, int> > locs;
vector<int> seq;
map<pair<int, int>, int> ids;
vector<int> n_above;
vector<int> n_below;
vector<bool> removed;
int main() {
cin >> m;
locs.resize(m);
for (int i = 0; i < m; i++) {
cin >> locs[i].fir... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long a, b, c, l;
long long ans = 0;
long long count(long long x, long long y, long long z, long long L) {
long long ret = 0;
for (long long i = max((long long)(0), x + y - z); i <= L; i++) {
long long now = min(L - i, z + i - x - y);
ret += (now + 1) * (now... | 13 |
#include <bits/stdc++.h>
using namespace std;
set<string> ans;
int dp[100010][2];
int main() {
string a;
string test;
cin >> a;
int len = a.size();
for (int i = len - 1; i >= 5; --i) {
if (i == len - 2) {
test.clear();
test += a[i];
test += a[i + 1];
ans.insert(test);
dp[i][0... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
int n, m;
int a[2005], s[2005];
long long dp[2005], pre[2005];
int main() {
scanf("%d %d", &n, &m);
memset(dp, 0, sizeof(dp));
for (int i = 1; i <= n; ++i) {
memcpy(pre, dp, sizeof(dp));
s[0] = 0;
for (int j = 1; j <= m; ++... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
char a[n][n];
int tot = 0;
for (int i = 0; i < n; i++) {
int ct = 0;
for (int j = 0; j < n; j++) {
cin >> a[i][j];
if (a[i][j] == 'C') ct++;
}
tot += ((ct * (ct - 1)) / 2);
}
for (int i = 0; i < n; i++)... | 0 |
#include <bits/stdc++.h>
using namespace std;
char s[2000];
int u[30], n, i, ans, l, r, c, j;
int main() {
scanf("%s%d", &s, &n);
for (i = 0; s[i]; i++) u[s[i] - 'a']++;
l = 1;
r = 414141;
while (l < r) {
c = (l + r) / 2;
ans = 0;
for (i = 0; i < 26; i++) ans += (u[i] + c - 1) / c;
if (ans > n... | 6 |
#include <bits/stdc++.h>
using namespace std;
double r, x1, x2, y, y3;
int main() {
cin >> r >> x1 >> y >> x2 >> y3;
double d = sqrt((x2 - x1) * (x2 - x1) + (y3 - y) * (y3 - y));
cout << ceil(d / (2 * r));
return 0;
}
| 6 |
#include <bits/stdc++.h>
using namespace std;
double A[505][505], R[505][505], B[505][505], P[505], T[505], D[505],
f[505][505];
int main() {
int N, M, K, n;
scanf("%d %d %d", &N, &M, &K);
n = N;
vector<bool> chk(N, 0);
for (int i = 0; i < N; i++) {
int x;
scanf("%d", &x);
chk[i] = x ? true : ... | 20 |
#include <bits/stdc++.h>
using namespace std;
int a[100];
int b[100];
int main() {
int n, s;
cin >> n >> s;
int s1 = s;
a[1] = 1;
if (s == 0 && n == 1) {
cout << 0 << " " << 0;
return 0;
}
if (s == 0) {
cout << -1 << " " << -1;
return 0;
}
if (9 * n < s) {
cout << -1 << " " << -1;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> v(n);
cin >> v[0];
long long ans = 1;
for (int i = 1; i < n; i++) {
cin >> v[i];
ans *= abs(v[i] - v[i - 1]);
ans = ans % m;
}
if (n > m) {
co... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5010;
int n, m, k, q;
vector<int> hv[N];
long long ans = 0, ad;
multiset<int> st;
int id[N];
int main() {
scanf("%d%d%d%d", &n, &m, &k, &q);
for (int i = 1, x, y; i <= k; i++) scanf("%d%d", &x, &y), hv[x].push_back(y);
for (int i = 1; i <= n; i++) {
... | 22 |
#include <bits/stdc++.h>
using namespace std;
const int CN = 1e6 + 10, P = 998244353;
int add(int x, int y) { return x + y >= P ? x + y - P : x + y; }
int n, fac[CN], ifac[CN], pre[CN], suf[CN], pc[CN], sc[CN], ans;
char ch[CN];
int C(int n, int m) {
return m < 0 || m > n ? 0 : (long long)fac[n] * ifac[m] % P * ifac[... | 18 |
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1e5 + 2;
int q, w, e, r;
int a[N], b[N];
int main() {
ios_base ::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> q >> w >> e >> r;
for (int i = 1; i <= q; i++) {
cin >> a[i];
}
for (int i = 1; i <= w; i++) {
cin >> b... | 1 |
#include <bits/stdc++.h>
#define HS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long
#define pll pair<ll,ll>
#define pb push_back
#define M 1000000007
#define lc '\n'
using namespace std;
int main()
{
// From editorial
HS
ll t;
cin>>t;
while(t--)
{
ll n;
... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
string s;
cin >> s;
int ig, it;
for (int i = 0; i < n; ++i) {
if (s[i] == 'G') {
ig = i;
}
if (s[i] == 'T') {
it = i;
}
}
if ((ig - it) % k != 0) {
cout << "NO";
return 0;
}
for (i... | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.