solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <stdio.h>
int main (){
char date[12];
scanf ("%s",date );
date[3] ='8';
printf("%s", date);
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
template <class _T>
inline _T sqr(const _T& x) {
return x * x;
}
template <class _T>
inline string tostr(const _T& a) {
ostringstream os("");
os << a;
return os.str();
}
const long double PI = 3.1415926535897932384626433832795L;
const long double EPS = 1e-8;
char TE... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char **argv) {
int N;
cin >> N;
bool A[N];
memset(A, 0, sizeof A);
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++) {
int B;
cin >> B;
if (i == j) {
assert(B == -1);
continue;
}
if (B == 1... | 1 |
#include <iostream>
using namespace std;
const int N = 500020 , mod = 998244353;
inline int qpow(int x , int y = mod - 2) {
int res = 1;
for(; y ; y >>= 1 , x = 1ll * x * x % mod)
if(y & 1) res = 1ll * res * x % mod;
return res;
}
int fac[N] , inv[N];
int C(int x , int y) {
if(y < 0 || y > x) return 0;
retur... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 505;
int dp[2][maxn][maxn];
int a[maxn];
inline void solve(void) {
int n, m, b;
long long M;
cin >> n >> m >> b >> M;
for (int i = (0); i < (n); i++) cin >> a[i];
for (int i = 1; i <= n; i++) {
for (int k = 0; k <= b; k++) {
for (int j =... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b;
cin >> a >> b;
if (a == 0) {
cout << -b * b << endl;
for (int i = 0; i < b; i++) cout << 'x';
cout << endl;
return 0;
}
if (b <= 1) {
cout << a * a - b * b << endl;
for (int i = 0; i < a; i++) cout << 'o';
f... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int sp = 0, dp = 0, s = 1;
int l = 0, r = n - 1;
while (l <= r) {
if (a[l] > a[r]) {
if (s == 1) {
sp += a[l];
s = 2;
} else {
dp... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int a, b;
cin >> a >> b;
int n = a + b;
set<int> ans;
{
int x = (n + 1) / 2;
int y = n / 2;
int init = 0;
if (x > a) {
int diff = x - a;
init += diff;
x -= ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000 + 10;
struct node {
node *ch[26], *fa, *nxt;
int go[26];
long long val, cnt;
long long dp;
void clean() { memset(this, 0, sizeof(node)); }
} pool[MAXN * 2], *first[MAXN];
node *root, *last, *cur;
inline void init() {
cur = pool;
root = ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double EPS = 1e-6;
const int MOD = (int)1e9 + 7;
const int maxn = (int)2e5 + 5;
const int logn = 20;
int dr[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dc[] = {0, 1, 1, 1, 0, -1, -1, -1};
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int g... | 2 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > gr;
int cnt[400010], root, rt, n;
bool ans[400010];
vector<pair<int, int> > subtr;
void dfscnt(int v, int p) {
cnt[v] = 1;
int tmp = 0;
for (auto i : gr[v]) {
if (i == p) {
continue;
}
dfscnt(i, v);
tmp = max(tmp, cnt[i]);
... | 3 |
#include <bits/stdc++.h>
using namespace std;
vector<int> v1;
pair<int, int> p1;
long long a[1234567], tr[1234567];
string s;
int dp[1001];
long long pow1(long long x, long long y) {
if (y == 0) return 1;
long long temp = pow1(x, y / 2) % 1000000007;
if (y % 2 == 0)
return (temp * temp) % 1000000007;
else
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, x, y, s;
int main() {
cin >> n;
while (n--) {
cin >> y;
if (y == 0 or y == x) {
s++;
x = 0;
} else {
if (y == 3) {
if (x == 2) {
x = 1;
} else if (x == 1) {
x = 2;
}
} else {
... | 1 |
#include<iostream>
#include<queue>
using namespace std;
int main() {
int n;
while (cin >> n, n) {
int e;
long long p, q;
long long number[4000];
bool t[4000];
queue<int>v;
for (int i = 0;i < 4000;i++) {
number[i] = 0;
t[i] = false;
}
for (int i = 0;i < n;i++) {
cin >> e >> p >> q;
number... | 0 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int num = 0, f = 1;
char ch = getchar();
while (ch > '9' || ch < '0') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
num = (num << 1) + (num << 3) + (ch ^ 48);
ch = getchar();
}
return num * f;
}... | 5 |
#include<bits/stdc++.h>
using namespace std;
int main(){
long long N;
cin>> N;
cout << (N + 1)/2 << endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int64_t M = 1e9 + 7, N = 300;
int d[N][N];
int main() {
ios::sync_with_stdio(false), cin.tie(nullptr);
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
if (i != j) d[i][j] = M;
string s1, s2;
cin >> s1 >> s2;
int n;
cin >> n;
for (int i ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 15;
const long long int inf = 1e18;
vector<vector<long long int> > a(20, vector<long long int>(110));
vector<vector<long long int> > b(20, vector<long long int>(110));
vector<vector<long long int> > c(20, vector<long long int>(110));
long long int n, m, ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, i, a, b, w[100000], x, z;
cin >> n >> a >> b;
for (i = 0; i < n; i++) cin >> w[i];
for (i = 0; i < n; i++) {
x = (a * w[i]) / b;
z = (b * x) / a;
if ((b * x) % a == 0)
cout << w[i] - z << " ";
else
cout << w[... | 2 |
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include... | 0 |
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
const int Maxn = 100010;
int a[Maxn], n;
bool cmp(int x, int y) { return x > y; }
int main() {
int i, j, k;
scanf("%d", &n);
for(i = 0; i < n; i++) scanf("%d", &a[i]);
sort(a, a+n, cmp);
for(i = 0; i <= n; i++){
if(... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main()
{
int x1,y1,x2,y2;
cin>>x1>>y1>>x2>>y2;
cout<<x2+y1-y2<<" "<<y2-x1+x2<<" "<<x1+y1-y2<<" "<<y1-x1+x2<<endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
static const int MAXN = 302;
static const int MODULUS = 1e9 + 7;
long long fact[MAXN], fact_inv[MAXN];
long long part[MAXN][MAXN] = {{0}};
inline long long qpow(long long base, int exp) {
long long ans = 1;
for (; exp; exp >>= 1, (base *= base) %= MODULUS)
if (exp & 1) (ans *= base) %= ... | 3 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
char ch = getchar();
long long x = 0, f = 1;
while (ch < '0' || ch > '9') f = ch == '-' ? -1 : 1, ch = getchar();
while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
return x * f;
}
int main(int argc, char *argv[]) {
i... | 2 |
#include <bits/stdc++.h>
using namespace std;
struct debugger {
template <typename T>
debugger& operator,(const T& v) {
cerr << v << " ";
return *this;
}
} dbg;
vector<long long> calc(vector<long long> vec, int pos) {
long long x = vec[pos];
vec[pos] = 0ll;
long long p = x / 14ll;
long long cnt = ... | 2 |
#include <iostream>
using namespace std;
int main(){
int N,n = 1;
cin >> N;
while(n<=N) n *= 2;
cout << n/2;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
long long int ans = INT_MAX;
void floyd(vector<vector<long long int>> graph, int n,
vector<vector<long long int>> &dist) {
for (int k = 0; k < n; k++) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (dist[i][k] + dist[k][j] < ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 300010;
long long n, a, b, val[N], pos[N];
string f;
int main() {
cin >> n >> f;
for (int i = 0; i < n; i++) pos[i] = i;
for (int i = 0; i < n; i++) {
long long j = i;
a = 0, b = 0;
while (j > 0 && f[j] < f[j - 1]) {
if (val[pos[j... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MN = 2e5 + 100;
int N;
int a[MN];
bool e[MN];
int f;
int c[3], C;
bool test(int v) {
for (int i = 0; i < C; i++)
if (!(c[i] % v)) return 0;
return 1;
}
void solve(void) {
f = 0;
scanf("%d", &N);
for (int i = 0; i < N; i++) scanf("%d", a + i);
sort(... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, m, q, s[10005][4];
int mtx[105][105];
int main() {
scanf("%d %d %d", &n, &m, &q);
for (int i = (1); i <= (q); i++) {
scanf("%d", &s[i][0]);
if (s[i][0] == 3)
scanf("%d %d %d", &s[i][1], &s[i][2], &s[i][3]);
else
scanf("%d", &s[i][1]);
}
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> g[100000];
long long c[100000];
long long w[100000];
int uu[100000], vv[100000];
int col[100000];
int st[100000], sz = 0;
vector<int> cyc;
int cycv = 0;
bool flag = true;
bool dfs(int v, int co) {
st[sz++] = v;
col[v] = co;
for (int e : g[v]) {
... | 4 |
#include<bits/stdc++.h>
using namespace std;
int main() {
int h, n;
scanf("%d%d", &h, &n);
for(int i=0;i<n;i++) {
int x;
scanf("%d", &x);
if(h>0) h-=x;
}
puts(h>0?"No":"Yes");
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, d, t, time = 0;
scanf("%d %d", &n, &d);
if ((n - 1) * 10 >= d)
printf("-1");
else {
for (i = 0; i < n; ++i) {
scanf("%d", &t);
time += t;
}
time += (n - 1) * 10;
if (time == d)
printf("%d", (n - 1) * 2);
... | 1 |
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>
using namespace std;
int main()
{
long n, u, k, r, v1, c1;
const long INF = 0xFFFFFFFF;
cin >> n >> k >> r;
vector<vector<long> > v(n), c(n);
vector<long> w(n, INF);
typedef pair<long, long> wt;
priority_queue<wt... | 0 |
#include <algorithm>
#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;
long long gcd(long long x, long long y){
if(x < y) swap(x,y);
while(y){
x %= y;
swap(x,y);
}
return x;
}
int main(){
long long n, m;
cin >> n >> m;
vector<long long> A(n);
vector<double> P(n);
f... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int x, y = 0, k = 0, t = 0;
int indeex[101];
int arr[102];
cin >> x;
for (int i = 1; i <= 7; i++) {
cin >> arr[i];
}
for (int i = 1; i <= 7; i++) {
t += arr[i];
if (t >= x) {
cout << i;
return 0;
} else if (i ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> vec;
int cnt = 0;
for (int i = max(0, n - 90); i <= n; i++) {
int tmp = i;
int ans = i;
while (tmp) {
ans += tmp % 10;
tmp /= 10;
}
if (ans == n) {
vec.push_back(i);
cnt++;
}... | 3 |
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ALL(a) (a).begin(),(a).end()
#define DEBUG(a) "(" << #a << ": " << (a) << ")"
templa... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
const int inf = 0x7f7f7f7f;
struct node {
int a, b;
bool operator<(const node& x) const {
if (x.b == b) return a < x.a;
return b < x.b;
}
} nod[maxn];
int main() {
long long n, r, avg;
while (~scanf("%I64d%I64d%I64d", &n, &r, &avg... | 3 |
#include <bits/stdc++.h>
int dr[] = {2, 2, -2, -2, 1, -1, 1, -1};
int dc[] = {1, -1, 1, -1, 2, 2, -2, -2};
int dr1[] = {0, 0, 0, 1, 1, 1, -1, -1, -1};
int dc1[] = {-1, 0, 1, -1, 0, 1, -1, 0, 1};
int dr2[] = {0, 0, 1, -1};
int dc2[] = {1, -1, 0, 0};
using namespace std;
long long int mark[3000005];
int main() {
string... | 4 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma loop_opt(on)
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
using ld = long double;
mt19937 mtrd(chrono::steady_clock::now().time_since_epoch().count());
const int mod = 1000000007;
const int m... | 4 |
#include <bits/stdc++.h>
const int N = 2350;
const int INF = 0x3f3f3f3f;
using namespace std;
const int M = 450;
int mp1[M][M], mp2[M][M];
int main() {
int n, m, a, b;
while (scanf("%d%d", &n, &m) == 2) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (i == j)
mp1[i][j]... | 1 |
#include <iostream>
using namespace std;
int a[6];
string s;
void C(int i,int j,int k,int l){
int t;t=a[i];a[i]=a[j];a[j]=a[k];a[k]=a[l];a[l]=t;
}
int main(){
for(int i=0;i<6;i++){
cin>>a[i];
}
cin>>s;
for(int i=0;i<s.size();i++){
if(s[i]=='E')for(int j=0;j<3;j++)C(0,2,5,3);
if(s[i]=='W')C(0,2... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
long long a[N + 100], pre[N + 100];
long long A, B, Q;
int n;
const int MAXL = 20;
const int INF = 0x3f3f3f3f;
struct abc {
long long pre2[MAXL + 5], need[N + 10];
long long fmax[N + 10][MAXL + 5];
void init(int n) {
pre2[0] = 1;
for (i... | 3 |
#include <bits/stdc++.h>
int n, m;
std::vector<int> v[1111111];
int x[1111111], y[1111111], l[1111111];
int fa[1111111];
int rt(int x) { return (fa[x]) ? fa[x] = rt(fa[x]) : x; }
int f[1111111][22], dep[1111111];
int lca(int x, int y) {
if (dep[x] < dep[y]) x ^= y ^= x ^= y;
register int i;
for (i = 20; ~i; i--)
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 2005, MOD = 1e9 + 7;
int n, d, C[MAX];
vector<int> G[MAX];
long long dfs(int nod, int p, int val, int ni) {
if (C[nod] < val || C[nod] > val + d || (C[nod] == val && nod < ni)) return 1;
long long ans = 1;
for (int i = 0; i < G[nod].size(); i++) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const int M = 200005;
const int MAX_VERTEX = N * 5 * 2;
const int MOD = 1e9 + 7;
int vertexCount;
vector<pair<int, int>> adj[MAX_VERTEX];
int start[N];
int dist[MAX_VERTEX];
int n, m;
pair<int, int> elist[M];
void addEdge(int from, int to, int w) { adj... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int n, m, x;
cin >> n >> m;
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
set<int> towers;
for (int i = 0; i < m; i++) {
cin >> x;
towers.insert(x);
}
int ans = 0;
for (int cur :... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 65536 * 2;
const long long INF = 1e10;
int main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
long long n;
cin >> n;
vector<long long> t;
set<long long> a;
for (long long i = 0; i < n; i++) {
long long x;
cin >> x;... | 1 |
#include <bits/stdc++.h>
const int maxn = 100010;
const double EPS = 1e-6;
using namespace std;
int v[26];
int main() {
int n, m;
cin >> n >> m;
string s;
cin >> s;
for (int i = 0; i < (s.size()); ++i) v[s[i] - 'a']++;
int flag = 1;
for (int i = 0; i < (26); ++i) {
if (v[i] > m) flag = 0;
}
if (fl... | 1 |
#include <bits/stdc++.h>
using namespace std;
using namespace placeholders;
const int MOD = 1000000007;
long long getPhi(long long n) {
long long ret = 1;
for (long long i = 2; i * i <= n; ++i) {
if (n % i) continue;
ret *= i - 1;
n /= i;
for (; n % i == 0; n /= i) ret *= i;
}
if (n > 1) ret *= ... | 5 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000000000")
using namespace std;
const long long int INF = 2e9;
void take(string &f, long long int &ab, long long int &ae, long long int &ina) {
ab = ae = ina = 0;
if (f[0] == 'C')
ab = 2;
else if (f[0] == 'A')
ab = 1;
if (f[(long long int)(... | 4 |
#include <bits/stdc++.h>
using namespace std;
int Max = 100000000;
void Floyd_Warshall(int n, vector<vector<int>>& MinCost) {
for (int k = 0; k < n; k++)
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
MinCost[i][j] = min(MinCost[i][j], MinCost[i][k] + MinCost[k][j]);
}
void Count_Min_Edge(i... | 5 |
#include<bits/stdc++.h>
using namespace std;
int n,m,k;
int main()
{
scanf("%d%d%d",&n,&m,&k);
n=max(n,m);
printf("%d\n",k/n+(k%n!=0));
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
scanf("%d %d", &n, &k);
int a[500001];
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
map<int, int> already;
map<int, int> last_seen;
int left = 1;
int right = 1;
int counter = 1;
already[a[right]]++;
int ans_right = -1, ans_le... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long a, b, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, row = 0, col = 0;
int main() {
long long t;
a = 0;
b = 0;
c = 0;
d = 0;
e = 0;
f = 0;
g = 0;
h = 0;
row = 0;
col = 0;
cin >> a;
string s;
if (a == 24) {
cin >> s;
b = s.size();
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
long long sum = 0;
long long arr[n], arr1[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
arr1[i] = arr[i];
}
sort(arr, arr + n);
sort(arr1, arr1 + n);
reverse(arr, arr + n);
for (int i = 0; i < n; i++) {
... | 3 |
#include <bits/stdc++.h>
const long long mod = 998244353ll;
using namespace std;
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n;
cin >> n;
vector<long long> a(2 * n);
for (long long i = 0; i < (2 * n); i++) cin >> a[i];
sort((a).begin(), (a).end());
long long LIM = 150005;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxd = 1000000007, N = 100000;
const double pi = acos(-1.0);
int n, pre[30], suf[30], len;
long long dp[100100][30];
char s[100100];
int read() {
int x = 0, f = 1;
char ch = getchar();
while ((ch < '0') || (ch > '9')) {
if (ch == '-') f = -1;
ch = ge... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <typename G1, typename G2 = G1, typename G3 = G1>
struct triple {
G1 first;
G2 second;
G3 T, Fo;
};
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<long long> mx(n, 1e9);
vector<long long> s(n);
vector<trip... | 3 |
#include<bits/stdc++.h>
using namespace std;
int main() {
string s;
cin>>s;
int n = s.length();
int i = 0;
int ac = 0;
long long ans = 0;
while(i+1 < n) {
if(s[i] == 'A') {
ac++;
i++;
}
else if(s[i] == 'B' && s[i+1] == 'C') {
ans+=ac;
i+=2;
}
else ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, q, t, k, d, f[110], sol, i, x;
set<int> s;
int main() {
cin.sync_with_stdio(0);
cout.sync_with_stdio(0);
cin >> n >> q;
for (; q; q--) {
cin >> t >> k >> d;
for (i = 1; i <= n; i++)
if (f[i] < t) s.insert(i);
if (s.size() < k) {
cout <... | 3 |
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<c... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
char a[N], b[N];
int n, m, K, fail[N], pre[N], aft[N];
void cul(char *A, char *B, int *res) {
int i, j;
for (i = 2, j = 0; i <= m; i++) {
while (j && B[j + 1] != B[i]) j = fail[j];
if (B[j + 1] == B[i]) j++;
fail[i] = j;
}
res[0] =... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e3 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 998244353;
int n;
long long a[MAXN][MAXN];
long long ans[MAXN];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) scanf("%lld", &a[i][j]);
long long temp =... | 2 |
#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
int main() {
int n, x;
cin >> n;
int s = 0;
for (int i = 0; i < n; ++i) {
cin >> x;
++mp[x];
s = max(s, mp[x]);
}
cout << s << endl;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10, MOD = 10567, MAXN = 1e12 + 10, LG = 20, M = 1e7,
P = 727, Sq = 100;
const long long inf = 2e18 + 10;
vector<int> v1[N], v2[N], ans1, ans2;
vector<pair<int, int> > ret1, ret2;
int main() {
int n, m, mx1 = 0, mx2 = 0;
cin >> n >> m;
for... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<pair<long long, int> > a(n);
for (int i = 0; i < n; i++) {
int k, x;
cin >> k;
for (int j = 1; j <= k; j++) {
cin >> x;
a[i].first = (a[i].first > x ? a[i].first : x);
}
a[i].second = k;
}
sort... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long n, p;
string s;
long long arr[1005], temp[1005];
bool possible(long long pos) {
for (long long i = 0; i <= n; i++) temp[i] = arr[i];
for (long long i = pos; i <= n; i++) {
long long start = (i == pos ? temp[i] + 1 : 0);
temp[i] = -1;
for (long long... | 1 |
#include<cstdio>
#include<queue>
#define mk make_pair
using namespace std;
typedef pair<int,int> pr;
const int N=200005;
int n,cnt;
int a[N],b[N];
long long ans;
priority_queue<pr>Q;
int main() {
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
for(int i=1;i<=n;i++) {
scanf("%d",&b[i]);
if(b[i]!=a[i])... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int a[N];
int n;
long long solve(long long x) {
long long ans = 0;
long long sum = 0;
for (int i = 1; i <= n; i++) {
sum = (sum + a[i]) % x;
ans += min(sum, x - sum);
}
return ans;
}
int main() {
long long sum = 0;
scanf("%d", &... | 5 |
#include <bits/stdc++.h>
using namespace std;
int f[200500][10][10], n, a[200500], ans;
char s[200500];
long long read() {
long long x = 0, f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') f = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = x * 10 + ch - '0';
ch = getchar();
... | 1 |
#include <bits/stdc++.h>
int a, b, c, x, y, z;
int main() {
scanf("%d %d %d", &a, &b, &c);
y = (a - b + c) / 2;
x = a - y;
z = c - y;
if (x + y != a || y + z != c || z + x != b || y < 0 || x < 0 || z < 0)
printf("Impossible\n");
else
printf("%d %d %d\n", x, z, y);
scanf("\n");
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
vector<int> to[MAXN], from[MAXN];
int par[MAXN];
bool visited[MAXN];
void dfs(int u)
{
visited[u] = 1;
for (auto v : to[u])
{
if (visited[v])
continue;
bool ok = 1;
for (auto w : from[v])
{
if (!visited[w])
{... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m, h, f[1000100], r[1000100];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m >> h;
for (int i = 0; i < m; i++) {
cin >> f[i];
}
for (int i = 0; i < n; i++) {
cin >> r[i];
}
for (int i = 0; i < n; i++) {
for (in... | 2 |
#include <bits/stdc++.h>
using namespace std;
int he[1000050 >> 1], ne[1000050 << 1], to[1000050 << 1], tot;
int n, m, ds;
const int inf = 1e9;
inline void addedge(int x, int y) {
to[++tot] = y;
ne[tot] = he[x];
he[x] = tot;
}
vector<int> v[1000050], ve[1000050];
int dfn[1000050 >> 1], low[1000050 >> 1], cnt, st[... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long int t, i, j, n, x, k, last[300005], dif[300005], d, sol[300005];
int main(int argc, const char* argv[]) {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> t;
while (t--) {
cin >> n;
for (i = 1; i <= n; i++) {
last[i] = -1;
dif[i] = -1;
... | 1 |
#include <iostream>
using namespace std;
int main() {
int n;
while (cin >> n, n != 0) {
int k = n / 4;
int sum = 0;
for (int i = 0; i < k; i++) {
int hit; cin >> hit;
sum += hit;
}
cout << sum << endl;
}
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long int n;
cin >> n;
for (int i = 0; i < n; i++) {
cout << i + 2 << " ";
}
cout << endl;
}
int main() {
long long int t;
cin >> t;
while (t--) solve();
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> a(6), b(3);
for (int i = 0; i < 6; i++) {
cin >> a[i];
}
int min1, min2, ans;
if (a[4] > a[5]) {
min1 = a[0] > a[3] ? a[3] : a[0];
a[3] -= min1;
ans = min1 * a[4];
min2 = a[1] > a[2] ? a[2] : a[1];
min2 = min2 > a[3... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int n;
cin >> n;
long long int ar[n];
for (int i = 0; i < n; i++) cin >> ar[i];
sort(ar, ar + n);
long long int l = count(ar, ar + n, ar[0]);
long long int b = count(ar, ar + n, ar[n -... | 2 |
#include <bits/stdc++.h>
using namespace std;
struct pt {
int x, y;
pt(int x, int y) { this->x = x, this->y = y; }
};
bool cmp(pt a, pt b) { return a.x < b.x || a.x == b.x && a.y < b.y; }
bool cw(pt a, pt b, pt c) {
return 1LL * a.x * (b.y - c.y) + 1LL * b.x * (c.y - a.y) +
1LL * c.x * (a.y - b.y) <
... | 3 |
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
const int MOD_ONE = 1e9 + 7;
const int INF = 2e5 + 5;
using ll = long long;
using db = double;
int dx[4] = {1, -1, 0, 0}, dy[4] = {0, 0, 1, -1};
int n, m;
string s1, s2;
int m... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> a;
vector<int> b;
int n = 0, aux = 0, flag = 1, pos = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> aux;
if (aux) {
a.push_back(aux);
}
}
for (int i = 0; i < n; i++) {
cin >> aux;
if (aux) {
b.push_b... | 1 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long a, b, c, d;
scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
printf("%lld %lld %lld\n", b, c, c);
}
int main() {
int t;
scanf("%d", &t);
while (t--) solve();
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int mo = 1000000009, mm = 100010;
int t, n, m, k, L, R, top, stk[mm], l[mm], r[mm];
pair<int, int> p[mm], f[mm], rg[mm];
pair<int, int> ask(int t, int L, int R) {
if ((!t) || (L > rg[t].second) || (R < rg[t].first)) return make_pair(-1, 0);
if ((L <= rg[t].first) ... | 4 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mxN=5e5, M=1e9+7;
int n, m;
ll iv[mxN+1], f1[mxN+1], f2[mxN+1];
ll nck(int n, int k) {
return f1[n]*f2[k]%M*f2[n-k]%M;
}
int main() {
iv[1]=1;
for(int i=2; i<=mxN; ++i)
iv[i]=M-M/i*iv[M%i]%M;
f1[0]=f2[0]=1;
for(int i=1; i<=mxN; ++i) {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d, e, f, g, h, m, n, cnt, pos, ans, bb[11111];
int main() {
cin >> a >> b >> c;
for (int i = 1; i <= a; ++i) {
cin >> bb[i];
}
sort(bb + 1, bb + 1 + a);
if (c >= b) {
cout << 0;
return 0;
}
for (int i = a; i > 0; --i) {
c += ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, m, item, sum = 0, a, b, c, d;
cin >> a >> b >> c >> d;
if (a == d) {
if (a == 0 && c != 0) {
cout << "0" << endl;
return 0;
}
cout << "1" << endl;
} else {
cout << "0" << endl;
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 + 3;
int n, m, mark[MAXN];
vector<int> g[MAXN];
pair<int, int> e[MAXN];
void dfs(int, int = 1);
int main() {
cin >> n >> m;
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
e[i] = {u, v};
}
for (int i = 0; i < m; i++)
if (e... | 4 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:20000000")
using namespace std;
int ri() {
int x;
scanf("%d", &x);
return x;
}
long long rll() {
long long x;
scanf("%lld", &x);
return x;
}
vector<int> rUP[10];
vector<int> rDOWN[10];
long long UP[10][200500];
int cntUP[10];
long long DOWN[10][200500... | 5 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> adj[100010];
bool vis[100010];
long long n, m, total = 0;
long long cc[100010];
void dfs(long long s, long long sum) {
if (vis[s]) return;
vis[s] = 1;
if (cc[s])
sum++;
else
sum = 0;
if (sum > m) return;
if (s != 1 && adj[s].size() == 1... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int n = s.length();
bool sign = false;
for (int i = 0; i < n; i++) {
if (s[i] == 'a' && !sign) continue;
if (s[i] == 'a' && sign) break;
s[i]--;
sign = true;
}
if (!sign) s[n - 1] = 'z';
cout << s << '\n';
}
| 1 |
#include <iostream>
#include <list>
using namespace std;
int main(void)
{
int n;
while (1){
list<int> lst_taro, lst_hana;
char flag[201] = {0};
cin >> n;
if (n == 0){
break;
}
for (int i = 0; i < n; i++){
int c;
cin >> c;
lst_taro.push_back(c);
flag[c] = 1;
}
lst_taro.sort();
f... | 0 |
#include <bits/stdc++.h>
using namespace std;
const signed int inf = (signed)(~0u >> 1), Val = 1e9;
typedef class SegTreeNode {
public:
int val;
SegTreeNode *l, *r;
SegTreeNode() {}
void pushUp() {
if (l) val = l->val;
if (r) val = max(val, r->val);
}
} SegTreeNode;
SegTreeNode pool[2000000];
SegTree... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a = 0, b = 0, c, n, t;
cin >> n >> t;
vector<long long> p;
for (long long i = 0; i < n; i++) {
cin >> c;
p.push_back(c);
}
a = 0;
for (long long i = 1; i < n; i++) {
if (p[i] == p[i - 1]) {
a++;
p[i] = p[i - 1] + ... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long sum[1000006], mod = 1e9 + 7;
int main() {
int n;
while (scanf("%d", &n) == 1) {
memset(sum, 0, sizeof(sum));
sum[0] = 1;
int t;
for (int i = 0; i < n; ++i) {
scanf("%d", &t);
vector<int> d;
for (int j = 1; j * j <= t; ++j) {
... | 3 |
#include<bits/stdc++.h>
using namespace std;
int n, x, c, ans, now, dlt;
int main()
{
scanf("%d", &n);
for(int i = 1; i <= n; ++i)
{
dlt = 0;
scanf("%d", &x);
c = (int)log2(x);
if(x != (1 << c)) dlt = 1;
if(now < c) ans += c - now, now = c;
if(now > c) now = c, dlt = 0;
if(dlt) ++ans, ++now;
}
prin... | 0 |
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <random>
#include <cstdio>
#include <cstring>
#include <cmath>
// for i in f..<t { as swift
#define forin(i, f, t) for(auto i = f; i < t; i++)
using namespace std;
using ll = long long;
using XY = p... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
int p[N], l[N], e[N];
int x[N], y[N];
vector<int> qry[N];
stack<int> st;
int f[N];
int ans[N];
int s[N];
int find(int x) {
if (f[x] != x) f[x] = find(f[x]);
return f[x];
}
int main() {
int n, q;
scanf("%d", &n);
for (int i = 1; i <= n; i++) ... | 5 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.